home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / workbench / term_4.8 / extras / source / term-source.lha / ARexxCommands.c < prev    next >
C/C++ Source or Header  |  1997-10-03  |  83KB  |  4,657 lines

  1. /*
  2. **    ARexxCommands.c
  3. **
  4. **    ARexx interface command support routines
  5. **
  6. **    Copyright © 1990-1997 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* Cheapo shortcuts */
  17.  
  18. #define Args        Pkt->Array
  19. #define ResultCode    Pkt->Results
  20.  
  21.     /* ScanNodeFilter(UBYTE *Data,LONG Size,struct List *List,UBYTE Mask,UBYTE **DataPtr):
  22.      *
  23.      *    Scans a data buffer for matches with the names of the list nodes. It
  24.      *    will return the matching node name and place the address where the
  25.      *    matching node name was found in the input buffer in DataPtr. If nothing
  26.      *    is found, NULL will be returned.
  27.      */
  28.  
  29. STATIC STRPTR
  30. ScanNodeFilter(UBYTE *Data,LONG Size,struct List *List,UBYTE Mask,UBYTE **DataPtr)
  31. {
  32.     STRPTR Result;
  33.     UBYTE Char;
  34.  
  35.         /* This is where the result of the search will be placed. */
  36.  
  37.     Result = NULL;
  38.  
  39.         /* Run down the input string. */
  40.  
  41.     while(Size--)
  42.     {
  43.             /* Get the next character, promote it to upper case
  44.              * and strip off the high order bit if necessary.
  45.              */
  46.  
  47.         if(Char = ToUpper((*Data++) & Mask))
  48.         {
  49.             struct WaitNode *Node;
  50.             UBYTE MatchChar;
  51.  
  52.                 /* Try to find the nodes in which the next character of the
  53.                  * name matches the character we just picked from the string.
  54.                  */
  55.  
  56.             for(Node = (struct WaitNode *)List->lh_Head ; Node->Node.ln_Succ ; Node = (struct WaitNode *)Node->Node.ln_Succ)
  57.             {
  58.                     /* This is the next character to match in the node name. */
  59.  
  60.                 MatchChar = ToUpper(Node->Node.ln_Name[Node->Count]) & Mask;
  61.  
  62.                     /* If it doesn't match the character we just got,
  63.                      * restart from the beginning of the node name.
  64.                      */
  65.  
  66.                 if(Char != MatchChar)
  67.                 {
  68.                     Node->Count = 0;
  69.  
  70.                     MatchChar = ToUpper(Node->Node.ln_Name[0]) & Mask;
  71.                 }
  72.  
  73.                     /* Does the character match? */
  74.  
  75.                 if(Char == MatchChar)
  76.                 {
  77.                         /* Increase the number of matching characters. */
  78.  
  79.                     Node->Count++;
  80.  
  81.                         /* Does the entire name match? */
  82.  
  83.                     if(!Node->Node.ln_Name[Node->Count])
  84.                     {
  85.                             /* If there is a response string
  86.                              * attached, send it. Otherwise
  87.                              * remember the matching string.
  88.                              */
  89.  
  90.                         if(Node->ResponseLen)
  91.                             SerWriteVerbatim(Node->Response,Node->ResponseLen,FALSE);
  92.                         else
  93.                             Result = Node->Node.ln_Name;
  94.  
  95.                         Node->Count = 0;
  96.                     }
  97.                 }
  98.             }
  99.  
  100.                 /* If we got something, return now. */
  101.  
  102.             if(Result != NULL)
  103.             {
  104.                 *DataPtr = Data;
  105.  
  106.                 return(Result);
  107.             }
  108.         }
  109.     }
  110.  
  111.         /* Couldn't find anything. */
  112.  
  113.     return(NULL);
  114. }
  115.  
  116. STRPTR
  117. RexxWait(struct RexxPkt *Pkt)
  118. {
  119.     enum    {    ARG_WAIT_NOECHO,ARG_TIMEOUT,ARG_WAIT_TEXT };
  120.  
  121.     UBYTE LocalBuffer[MAX_FILENAME_LENGTH];
  122.     struct List LocalList,*MatchList;
  123.     struct WaitNode LocalWaitNode;
  124.     ULONG Signals;
  125.     STRPTR Result;
  126.     LONG Timeout;
  127.     UBYTE Mask;
  128.     BOOL Echo;
  129.     BOOL Done;
  130.  
  131.     if(!ReadRequest || !WriteRequest)
  132.     {
  133.         ResultCode[0] = RC_WARN;
  134.  
  135.         return(NULL);
  136.     }
  137.  
  138.     if(Args[ARG_WAIT_NOECHO])
  139.         Echo = FALSE;
  140.     else
  141.         Echo = TRUE;
  142.  
  143.     if(Args[ARG_WAIT_TEXT])
  144.     {
  145.         LONG Len;
  146.  
  147.         NewList(&LocalList);
  148.  
  149.         CopyMem(Args[ARG_WAIT_TEXT],LocalBuffer,sizeof(LocalBuffer) - 1);
  150.         LocalBuffer[sizeof(LocalBuffer) - 1] = 0;
  151.  
  152.         Len = TranslateString(LocalBuffer,LocalBuffer);
  153.         LocalBuffer[Len] = 0;
  154.  
  155.         memset(&LocalWaitNode,0,sizeof(struct WaitNode));
  156.  
  157.         LocalWaitNode.Node.ln_Name = LocalBuffer;
  158.  
  159.         AddTail(MatchList = &LocalList,(struct Node *)&LocalWaitNode);
  160.     }
  161.     else
  162.     {
  163.         if(!GenericListCount(GenericListTable[GLIST_WAIT]))
  164.         {
  165.             ResultCode[0] = RC_ERROR;
  166.             ResultCode[1] = TERMERROR_LIST_IS_ALREADY_EMPTY;
  167.  
  168.             return(NULL);
  169.         }
  170.         else
  171.         {
  172.             struct WaitNode *Node;
  173.  
  174.             MatchList = (struct List *)GenericListTable[GLIST_WAIT];
  175.  
  176.             LockGenericList((struct GenericList *)MatchList);
  177.  
  178.             for(Node = (struct WaitNode *)MatchList->lh_Head ; Node->Node.ln_Succ ; Node = (struct WaitNode *)Node->Node.ln_Succ)
  179.                 Node->Count = 0;
  180.         }
  181.     }
  182.  
  183.     if(Config->SerialConfig->StripBit8)
  184.         Mask = 0x7F;
  185.     else
  186.         Mask = 0xFF;
  187.  
  188.     if(Args[ARG_TIMEOUT])
  189.         Timeout = *(LONG *)Args[ARG_TIMEOUT];
  190.     else
  191.         Timeout = RexxTimeoutVal;
  192.  
  193.     if(Timeout)
  194.         StartTime(Timeout,0);
  195.  
  196.     Lock_xOFF();
  197.     Clear_xOFF();
  198.  
  199.     Result = NULL;
  200.     Done = FALSE;
  201.  
  202.     do
  203.     {
  204.         Signals = (*SerialWaitForData)(SIG_WINDOW | SIG_BREAK | SIG_TIMER);
  205.  
  206.         if(Signals & SIG_WINDOW)
  207.             while(RunJob(WindowJob));
  208.  
  209.         if(Signals & SIG_SERIAL)
  210.         {
  211.             ULONG Length;
  212.  
  213.             if(Length = (*SerialGetWaiting)())
  214.             {
  215.                 if(Length > SerialBufferSize / 2)
  216.                     Length = SerialBufferSize / 2;
  217.  
  218.                 if(Length > Config->SerialConfig->Quantum)
  219.                     Length = Config->SerialConfig->Quantum;
  220.  
  221.                 if(Length = (*SerialRead)(ReadBuffer,Length))
  222.                 {
  223.                     BytesIn += Length;
  224.  
  225.                     if(Translate_CR_LF)
  226.                         Length = (*Translate_CR_LF)(ReadBuffer,Length);
  227.  
  228.                     if(Length)
  229.                     {
  230.                         UBYTE *NewData;
  231.  
  232.                         if(Result = ScanNodeFilter(ReadBuffer,Length,MatchList,Mask,&NewData))
  233.                         {
  234.                             ULONG NewLength;
  235.  
  236.                             NewLength = (ULONG)NewData - (ULONG)ReadBuffer;
  237.  
  238.                             if(NewLength + strlen(Result) != Length)
  239.                             {
  240.                                 DataHold = NewData;
  241.                                 DataSize = Length - NewLength;
  242.  
  243.                                 UpdateSerialJob();
  244.                             }
  245.  
  246.                             Length = NewLength;
  247.  
  248.                             Done = TRUE;
  249.                         }
  250.  
  251.                         if(Echo && Length)
  252.                             ConProcess(ReadBuffer,Length);
  253.                     }
  254.                 }
  255.             }
  256.         }
  257.  
  258.         if(Signals & (SIG_BREAK | SIG_TIMER))
  259.         {
  260.             if(!Result)
  261.                 ResultCode[0] = RC_WARN;
  262.  
  263.             Done = TRUE;
  264.         }
  265.     }
  266.     while(!Done);
  267.  
  268.     if(MatchList == (struct List *)GenericListTable[GLIST_WAIT])
  269.         UnlockGenericList((struct GenericList *)MatchList);
  270.  
  271.     Unlock_xOFF();
  272.  
  273.     StopTime();
  274.  
  275.     if(Result)
  276.         return(CreateResult(Result,ResultCode));
  277.     else
  278.         return(NULL);
  279. }
  280.  
  281. STATIC BOOL
  282. ExamineBeforeSending(STRPTR FileName,struct FileTransferInfo *Info,LONG *Results)
  283. {
  284.     BPTR FileLock;
  285.     BOOL Result;
  286.  
  287.     Result = FALSE;
  288.  
  289.     if(FileLock = Lock(FileName,ACCESS_READ))
  290.     {
  291.         D_S(struct FileInfoBlock,FileInfo);
  292.  
  293.         if(Examine(FileLock,FileInfo))
  294.         {
  295.             if(FileInfo->fib_DirEntryType < 0)
  296.             {
  297.                 UBYTE LocalBuffer[MAX_FILENAME_LENGTH];
  298.  
  299.                 if(NameFromLock(FileLock,LocalBuffer,sizeof(LocalBuffer)))
  300.                 {
  301.                     if(AddFileTransferNode(Info,LocalBuffer,FileInfo->fib_Size))
  302.                         Result = TRUE;
  303.                     else
  304.                     {
  305.                         Results[0] = RC_ERROR;
  306.                         Results[1] = ERROR_NO_FREE_STORE;
  307.                     }
  308.                 }
  309.                 else
  310.                 {
  311.                     Results[0] = RC_ERROR;
  312.                     Results[1] = IoErr();
  313.                 }
  314.             }
  315.             else
  316.             {
  317.                 Results[0] = RC_ERROR;
  318.                 Results[1] = ERROR_OBJECT_WRONG_TYPE;
  319.             }
  320.         }
  321.         else
  322.         {
  323.             Results[0] = RC_ERROR;
  324.             Results[1] = IoErr();
  325.         }
  326.  
  327.         UnLock(FileLock);
  328.     }
  329.     else
  330.     {
  331.         Results[0] = RC_ERROR;
  332.         Results[1] = IoErr();
  333.     }
  334.  
  335.     return(Result);
  336. }
  337.  
  338. STATIC BPTR
  339. ChangeDirBeforeSending(LONG Mode)
  340. {
  341.     BPTR NewDir = NULL;
  342.  
  343.     switch(Mode)
  344.     {
  345.         case TRANSFER_BINARY:
  346.  
  347.             if(Config->PathConfig->BinaryUploadPath[0])
  348.                 NewDir = Lock(Config->PathConfig->BinaryUploadPath,SHARED_LOCK);
  349.  
  350.             break;
  351.  
  352.         case TRANSFER_TEXT:
  353.  
  354.             if(Config->PathConfig->TextUploadPath[0])
  355.                 NewDir = Lock(Config->PathConfig->TextUploadPath,SHARED_LOCK);
  356.  
  357.             break;
  358.  
  359.         case TRANSFER_ASCII:
  360.  
  361.             if(Config->PathConfig->ASCIIUploadPath[0])
  362.                 NewDir = Lock(Config->PathConfig->ASCIIUploadPath,SHARED_LOCK);
  363.  
  364.             break;
  365.     }
  366.  
  367.     return(NewDir);
  368. }
  369.  
  370. STRPTR
  371. RexxSendFile(struct RexxPkt *Pkt)
  372. {
  373.     enum    {    ARG_SENDFILE_MODE,ARG_SENDFILE_NAMES };
  374.  
  375.     LONG Mode = TRANSFER_BINARY;
  376.  
  377.     if(Args[ARG_SENDFILE_MODE])
  378.         Mode = ToMode(Args[ARG_SENDFILE_MODE]);
  379.  
  380.     if(Mode == -1)
  381.     {
  382.         ResultCode[0] = RC_ERROR;
  383.         ResultCode[1] = ERROR_ACTION_NOT_KNOWN;
  384.     }
  385.     else
  386.     {
  387.         struct FileTransferInfo    *Info;
  388.         LONG FilesFound = 0;
  389.  
  390.         ResultCode[0] = RC_OK;
  391.  
  392.         if(Info = AllocFileTransferInfo())
  393.         {
  394.             struct GenericList *List = GenericListTable[GLIST_UPLOAD];
  395.             BPTR NewDir,OldDir;
  396.  
  397.             if(Args[ARG_SENDFILE_NAMES])
  398.             {
  399.                 STRPTR *Names;
  400.  
  401.                 Names = (STRPTR *)Args[ARG_SENDFILE_NAMES];
  402.  
  403.                 if(NewDir = ChangeDirBeforeSending(Mode))
  404.                     OldDir = CurrentDir(NewDir);
  405.  
  406.                 while(*Names && ResultCode[0] == RC_OK)
  407.                 {
  408.                     if(ExamineBeforeSending(*Names++,Info,ResultCode))
  409.                         FilesFound++;
  410.                 }
  411.  
  412.                 if(NewDir)
  413.                     UnLock(CurrentDir(OldDir));
  414.             }
  415.  
  416.             LockGenericList(List);
  417.  
  418.             if(GenericListCount(List) > 0 && ResultCode[0] == RC_OK)
  419.             {
  420.                 struct Node    *Node;
  421.  
  422.                 if(NewDir = ChangeDirBeforeSending(Mode))
  423.                     OldDir = CurrentDir(NewDir);
  424.  
  425.                 for(Node = (struct Node *)List->ListHeader.mlh_Head ; Node->ln_Succ && ResultCode[0] == RC_OK ; Node = Node->ln_Succ)
  426.                 {
  427.                     if(ExamineBeforeSending(Node->ln_Name,Info,ResultCode))
  428.                         FilesFound++;
  429.                 }
  430.  
  431.                 if(NewDir)
  432.                     UnLock(CurrentDir(OldDir));
  433.             }
  434.  
  435.             UnlockGenericList(List);
  436.  
  437.             if(ResultCode[0] == RC_OK)
  438.             {
  439.                 BlockWindows();
  440.  
  441.                 if(FilesFound)
  442.                 {
  443.                     ReadyFileTransferInfo(Info,TRUE);
  444.  
  445.                     FileTransferInfo = Info;
  446.                 }
  447.  
  448.                 switch(Mode)
  449.                 {
  450.                     case TRANSFER_ASCII:
  451.  
  452.                         if(ChangeProtocol(Config->TransferConfig->ASCIIUploadLibrary,Config->TransferConfig->ASCIIUploadType))
  453.                         {
  454.                             if(FilesFound)
  455.                                 StartSendXPR_FromList(TRANSFER_ASCII,FALSE);
  456.                             else
  457.                                 StartSendXPR_AskForFile(TRANSFER_ASCII,FALSE);
  458.                         }
  459.                         else
  460.                         {
  461.                             ResultCode[0] = RC_ERROR;
  462.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  463.                         }
  464.  
  465.                         ResetProtocol();
  466.  
  467.                         break;
  468.  
  469.                     case TRANSFER_TEXT:
  470.  
  471.                         if(ChangeProtocol(Config->TransferConfig->TextUploadLibrary,Config->TransferConfig->TextUploadType))
  472.                         {
  473.                             if(FilesFound)
  474.                                 StartSendXPR_FromList(TRANSFER_TEXT,FALSE);
  475.                             else
  476.                                 StartSendXPR_AskForFile(TRANSFER_TEXT,FALSE);
  477.                         }
  478.                         else
  479.                         {
  480.                             ResultCode[0] = RC_ERROR;
  481.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  482.                         }
  483.  
  484.                         ResetProtocol();
  485.  
  486.                         break;
  487.  
  488.                     case TRANSFER_BINARY:
  489.  
  490.                         if(ChangeProtocol(Config->TransferConfig->BinaryUploadLibrary,Config->TransferConfig->BinaryUploadType))
  491.                         {
  492.                             if(FilesFound)
  493.                                 StartSendXPR_FromList(TRANSFER_BINARY,FALSE);
  494.                             else
  495.                                 StartSendXPR_AskForFile(TRANSFER_BINARY,FALSE);
  496.                         }
  497.                         else
  498.                         {
  499.                             ResultCode[0] = RC_ERROR;
  500.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  501.                         }
  502.  
  503.                         ResetProtocol();
  504.  
  505.                         break;
  506.                 }
  507.  
  508.                 if(TransferFailed)
  509.                     ResultCode[0] = RC_ERROR;
  510.                 else
  511.                 {
  512.                     if(TransferAborted)
  513.                         ResultCode[0] = RC_WARN;
  514.                 }
  515.  
  516.                 ReleaseWindows();
  517.             }
  518.             else
  519.                 FreeFileTransferInfo(Info);
  520.         }
  521.         else
  522.         {
  523.             ResultCode[0] = RC_ERROR;
  524.             ResultCode[1] = ERROR_NO_FREE_STORE;
  525.         }
  526.     }
  527.  
  528.     return(NULL);
  529. }
  530.  
  531. STRPTR
  532. RexxSelect(struct RexxPkt *Pkt)
  533. {
  534.     enum    {    ARG_SELECT_NAME,ARG_SELECT_FROM,ARG_SELECT_NEXT,ARG_SELECT_PREVIOUS,
  535.                 ARG_SELECT_TOP,ARG_SELECT_BOTTOM
  536.             };
  537.  
  538.     LONG Index;
  539.  
  540.     if((Index = ToList(Args[ARG_SELECT_FROM])) == -1)
  541.     {
  542.         ResultCode[0] = RC_ERROR;
  543.         ResultCode[1] = TERMERROR_UNKNOWN_LIST;
  544.     }
  545.     else
  546.     {
  547.         if(Args[ARG_SELECT_NAME] && Index == GLIST_DIAL)
  548.         {
  549.             ResultCode[0] = RC_ERROR;
  550.             ResultCode[1] = TERMERROR_DATA_TYPES_INCOMPATIBLE;
  551.         }
  552.         else
  553.         {
  554.             struct GenericList *List;
  555.             STRPTR Result;
  556.  
  557.             List = GenericListTable[Index];
  558.  
  559.             if(Args[ARG_SELECT_NAME])
  560.             {
  561.                 STRPTR Buffer;
  562.  
  563.                 if(Buffer = CreateMatchBuffer(Args[ARG_SELECT_NAME]))
  564.                 {
  565.                     struct Node *Node;
  566.                     BOOL GotIt;
  567.  
  568.                     LockGenericList(List);
  569.  
  570.                     for(Node = (struct Node *)List->ListHeader.mlh_Head, GotIt = FALSE; !GotIt && Node->ln_Succ ; Node = Node->ln_Succ)
  571.                     {
  572.                         if(MatchBuffer(Buffer,Node->ln_Name))
  573.                         {
  574.                             List->ListNode = Node;
  575.  
  576.                             GotIt = TRUE;
  577.                         }
  578.                     }
  579.  
  580.                     if(!GotIt)
  581.                         ResultCode[0] = RC_WARN;
  582.  
  583.                     UnlockGenericList(List);
  584.  
  585.                     DeleteMatchBuffer(Buffer);
  586.                 }
  587.                 else
  588.                 {
  589.                     ResultCode[0] = RC_ERROR;
  590.                     ResultCode[1] = ERROR_NO_FREE_STORE;
  591.                 }
  592.             }
  593.             else
  594.             {
  595.                 if(Args[ARG_SELECT_NEXT])
  596.                 {
  597.                     if(!NextGenericListNode(List))
  598.                     {
  599.                         ResultCode[0] = RC_WARN;
  600.  
  601.                         return(NULL);
  602.                     }
  603.                 }
  604.  
  605.                 if(Args[ARG_SELECT_PREVIOUS])
  606.                 {
  607.                     if(!PrevGenericListNode(List))
  608.                     {
  609.                         ResultCode[0] = RC_WARN;
  610.  
  611.                         return(NULL);
  612.                     }
  613.                 }
  614.  
  615.                 if(Args[ARG_SELECT_TOP])
  616.                 {
  617.                     if(!FirstGenericListNode(List))
  618.                     {
  619.                         ResultCode[0] = RC_WARN;
  620.  
  621.                         return(NULL);
  622.                     }
  623.                 }
  624.  
  625.                 if(Args[ARG_SELECT_BOTTOM])
  626.                 {
  627.                     if(!LastGenericListNode(List))
  628.                     {
  629.                         ResultCode[0] = RC_WARN;
  630.  
  631.                         return(NULL);
  632.                     }
  633.                 }
  634.             }
  635.  
  636.             SharedLockGenericList(List);
  637.  
  638.             if(List->ListNode)
  639.                 Result = CreateResult(((struct Node *)List->ListNode)->ln_Name,ResultCode);
  640.             else
  641.             {
  642.                 ResultCode[0] = RC_WARN;
  643.  
  644.                 Result = NULL;
  645.             }
  646.  
  647.             UnlockGenericList(List);
  648.  
  649.             return(Result);
  650.         }
  651.     }
  652.  
  653.     return(NULL);
  654. }
  655.  
  656. STRPTR
  657. RexxSaveAs(struct RexxPkt *Pkt)
  658. {
  659.     enum    {    ARG_SAVEAS_NAME,ARG_SAVEAS_FROM };
  660.  
  661.     LONG Index = ToConfig(Args[ARG_SAVEAS_FROM]);
  662.  
  663.     if(Index == -1)
  664.     {
  665.         ResultCode[0] = RC_ERROR;
  666.         ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  667.     }
  668.     else
  669.     {
  670.         UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  671.         STRPTR FileName;
  672.  
  673.         if(Args[ARG_SAVEAS_NAME])
  674.             FileName = Args[ARG_SAVEAS_NAME];
  675.         else
  676.         {
  677.             struct FileRequester *FileRequest;
  678.             LONG TitleID;
  679.  
  680.             FileName = NULL;
  681.  
  682.             switch(Index)
  683.             {
  684.                 case DATATYPE_TRANSLATIONS:
  685.  
  686.                     TitleID = MSG_TRANSLATIONPANEL_SAVE_TRANSLATION_TABLES_TXT;
  687.                     break;
  688.  
  689.                 case DATATYPE_FUNCTIONKEYS:
  690.  
  691.                     TitleID = MSG_MACROPANEL_SAVE_MACRO_KEYS_TXT;
  692.                     break;
  693.  
  694.                 case DATATYPE_CURSORKEYS:
  695.  
  696.                     TitleID = MSG_CURSORPANEL_SAVE_CURSOR_KEYS_TXT;
  697.                     break;
  698.  
  699.                 case DATATYPE_FASTMACROS:
  700.  
  701.                     TitleID = MSG_FASTMACROPANEL_SAVE_FAST_MACRO_SETTINGS_TXT;
  702.                     break;
  703.  
  704.                 case DATATYPE_HOTKEYS:
  705.  
  706.                     TitleID = MSG_HOTKEYPANEL_SAVE_HOTKEYS_TXT;
  707.                     break;
  708.  
  709.                 case DATATYPE_SPEECH:
  710.  
  711.                     TitleID = MSG_SPEECHPANEL_SAVE_SPEECH_SETTINGS_TXT;
  712.                     break;
  713.  
  714.                 case DATATYPE_SOUND:
  715.  
  716.                     TitleID = MSG_SOUNDPANEL_SAVE_SOUNDS_TXT;
  717.                     break;
  718.  
  719.                 case DATATYPE_BUFFER:
  720.  
  721.                     TitleID = MSG_TERMMAIN_SAVE_BUFFER_TXT;
  722.                     break;
  723.  
  724.                 case DATATYPE_CONFIGURATION:
  725.  
  726.                     TitleID = MSG_TERMMAIN_SAVE_PREFERENCES_AS_TXT;
  727.                     break;
  728.  
  729.                 case DATATYPE_PHONEBOOK:
  730.  
  731.                     TitleID = MSG_PHONEPANEL_SAVE_PHONEBOOK_TXT;
  732.                     break;
  733.  
  734.                 case DATATYPE_SCREENTEXT:
  735.  
  736.                     TitleID = MSG_TERMMAIN_SAVE_SCREEN_ASCII_TXT;
  737.                     break;
  738.  
  739.                 case DATATYPE_SCREENIMAGE:
  740.  
  741.                     TitleID = MSG_TERMMAIN_SAVE_SCREEN_IFF_TXT;
  742.                     break;
  743.             }
  744.  
  745.             BlockWindows();
  746.  
  747.             DummyBuffer[0] = 0;
  748.  
  749.             if(FileRequest = SaveFile(Window,LocaleString(TitleID),NULL,NULL,DummyBuffer,sizeof(DummyBuffer)))
  750.             {
  751.                 FreeAslRequest(FileRequest);
  752.  
  753.                 FileName = DummyBuffer;
  754.             }
  755.  
  756.             ReleaseWindows();
  757.         }
  758.  
  759.         if(FileName)
  760.         {
  761.             switch(Index)
  762.             {
  763.                 case DATATYPE_TRANSLATIONS:
  764.  
  765.                     if(SendTable && ReceiveTable)
  766.                     {
  767.                         if(!SaveTranslationTables(FileName,SendTable,ReceiveTable))
  768.                         {
  769.                             ResultCode[0] = RC_ERROR;
  770.                             ResultCode[1] = IoErr();
  771.                         }
  772.                         else
  773.                         {
  774.                             strcpy(LastTranslation,FileName);
  775.  
  776.                             strcpy(Config->TranslationFileName,LastTranslation);
  777.  
  778.                             TranslationChanged = FALSE;
  779.                         }
  780.                     }
  781.                     else
  782.                         ResultCode[0] = RC_WARN;
  783.  
  784.                     break;
  785.  
  786.                 case DATATYPE_FUNCTIONKEYS:
  787.  
  788.                     if(!WriteIFFData(FileName,MacroKeys,sizeof(struct MacroKeys),ID_KEYS))
  789.                     {
  790.                         ResultCode[0] = RC_ERROR;
  791.                         ResultCode[1] = IoErr();
  792.                     }
  793.                     else
  794.                     {
  795.                         strcpy(LastMacros,FileName);
  796.  
  797.                         strcpy(Config->MacroFileName,LastMacros);
  798.  
  799.                         MacroChanged = FALSE;
  800.                     }
  801.  
  802.                     break;
  803.  
  804.                 case DATATYPE_CURSORKEYS:
  805.  
  806.                     if(!WriteIFFData(FileName,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  807.                     {
  808.                         ResultCode[0] = RC_ERROR;
  809.                         ResultCode[1] = IoErr();
  810.                     }
  811.                     else
  812.                     {
  813.                         strcpy(LastCursorKeys,FileName);
  814.  
  815.                         strcpy(Config->CursorFileName,LastCursorKeys);
  816.  
  817.                         CursorKeysChanged = FALSE;
  818.                     }
  819.  
  820.                     break;
  821.  
  822.                 case DATATYPE_FASTMACROS:
  823.  
  824.                     if(!SaveFastMacros(FileName,&FastMacroList))
  825.                     {
  826.                         ResultCode[0] = RC_ERROR;
  827.                         ResultCode[1] = IoErr();
  828.                     }
  829.                     else
  830.                     {
  831.                         strcpy(LastFastMacros,FileName);
  832.  
  833.                         strcpy(Config->FastMacroFileName,LastFastMacros);
  834.  
  835.                         FastMacrosChanged = FALSE;
  836.                     }
  837.  
  838.                     break;
  839.  
  840.                 case DATATYPE_HOTKEYS:
  841.  
  842.                     if(!WriteIFFData(FileName,&Hotkeys,sizeof(struct Hotkeys),ID_HOTK))
  843.                     {
  844.                         ResultCode[0] = RC_ERROR;
  845.                         ResultCode[1] = IoErr();
  846.                     }
  847.                     else
  848.                     {
  849.                         strcpy(LastKeys,FileName);
  850.  
  851.                         strcpy(Config->HotkeyFileName,LastKeys);
  852.  
  853.                         HotkeysChanged = FALSE;
  854.                     }
  855.  
  856.                     break;
  857.  
  858.                 case DATATYPE_SPEECH:
  859.  
  860.                     if(!WriteIFFData(FileName,&SpeechConfig,sizeof(struct SpeechConfig),ID_SPEK))
  861.                     {
  862.                         ResultCode[0] = RC_ERROR;
  863.                         ResultCode[1] = IoErr();
  864.                     }
  865.                     else
  866.                     {
  867.                         strcpy(LastSpeech,FileName);
  868.  
  869.                         strcpy(Config->SpeechFileName,LastSpeech);
  870.  
  871.                         SpeechChanged = FALSE;
  872.                     }
  873.  
  874.                     break;
  875.  
  876.                 case DATATYPE_SOUND:
  877.  
  878.                     if(!WriteIFFData(FileName,&SoundConfig,sizeof(struct SoundConfig),ID_SOUN))
  879.                     {
  880.                         ResultCode[0] = RC_ERROR;
  881.                         ResultCode[1] = IoErr();
  882.                     }
  883.                     else
  884.                     {
  885.                         strcpy(LastSound,FileName);
  886.  
  887.                         strcpy(Config->SoundFileName,LastSound);
  888.  
  889.                         SoundChanged = FALSE;
  890.                     }
  891.  
  892.                     break;
  893.  
  894.                 case DATATYPE_BUFFER:
  895.  
  896.                     if(BufferLines && Lines)
  897.                     {
  898.                         BPTR SomeFile;
  899.  
  900.                         if(SomeFile = OpenToAppend(FileName,NULL))
  901.                         {
  902.                             LONG i,Len;
  903.  
  904.                                 /* Obtain the semaphore required
  905.                                  * to gain access to the line buffer
  906.                                  */
  907.  
  908.                             SafeObtainSemaphoreShared(&BufferSemaphore);
  909.  
  910.                             for(i = 0 ; i < Lines ; i++)
  911.                             {
  912.                                 Len = BufferLines[i][-1];
  913.  
  914.                                 if(Len)
  915.                                 {
  916.                                     if(FWrite(SomeFile,BufferLines[i],Len,1) != 1)
  917.                                     {
  918.                                         ResultCode[0] = RC_ERROR;
  919.                                         ResultCode[1] = IoErr();
  920.  
  921.                                         break;
  922.                                     }
  923.                                 }
  924.  
  925.                                 if(FPrintf(SomeFile,"\n") < 1)
  926.                                 {
  927.                                     ResultCode[0] = RC_ERROR;
  928.                                     ResultCode[1] = IoErr();
  929.  
  930.                                     break;
  931.                                 }
  932.                             }
  933.  
  934.                             ReleaseSemaphore(&BufferSemaphore);
  935.  
  936.                             Close(SomeFile);
  937.  
  938.                             AddProtection(FileName,FIBF_EXECUTE);
  939.  
  940.                             if(Config->MiscConfig->CreateIcons)
  941.                                 AddIcon(FileName,FILETYPE_TEXT,TRUE);
  942.  
  943.                             BufferChanged = FALSE;
  944.                         }
  945.                         else
  946.                         {
  947.                             ResultCode[0] = RC_ERROR;
  948.                             ResultCode[1] = IoErr();
  949.                         }
  950.                     }
  951.                     else
  952.                     {
  953.                         ResultCode[0] = RC_ERROR;
  954.                         ResultCode[1] = TERMERROR_NO_DATA_TO_PROCESS;
  955.                     }
  956.  
  957.                     break;
  958.  
  959.                 case DATATYPE_CONFIGURATION:
  960.  
  961.                     if(!WriteConfig(FileName,Config))
  962.                     {
  963.                         ResultCode[0] = RC_ERROR;
  964.                         ResultCode[1] = IoErr();
  965.                     }
  966.                     else
  967.                     {
  968.                         strcpy(LastConfig,FileName);
  969.  
  970.                         ConfigChanged = FALSE;
  971.                     }
  972.  
  973.                     break;
  974.  
  975.                 case DATATYPE_PHONEBOOK:
  976.  
  977.                     if(!SavePhonebook(FileName,GlobalPhoneHandle))
  978.                     {
  979.                         ResultCode[0] = RC_ERROR;
  980.                         ResultCode[1] = IoErr();
  981.                     }
  982.                     else
  983.                     {
  984.                         strcpy(LastPhone,FileName);
  985.                         strcpy(Config->PhonebookFileName,LastPhone);
  986.  
  987.                         PhonebookChanged = FALSE;
  988.                     }
  989.  
  990.                     break;
  991.  
  992.                 case DATATYPE_SCREENTEXT:
  993.  
  994.                     if(RasterEnabled)
  995.                     {
  996.                         BPTR SomeFile;
  997.  
  998.                         if(SomeFile = OpenToAppend(FileName,NULL))
  999.                         {
  1000.                             LONG     i,j;
  1001.                             UBYTE    *Buffer;
  1002.  
  1003.                             for(i = 0 ; i < RasterHeight ; i++)
  1004.                             {
  1005.                                 Buffer = &Raster[i * RasterWidth];
  1006.  
  1007.                                 j = LastColumn;
  1008.  
  1009.                                 while(j >= 0 && Buffer[j] == ' ')
  1010.                                     j--;
  1011.  
  1012.                                 if(j >= 0)
  1013.                                 {
  1014.                                     if(!FWrite(SomeFile,Buffer,j + 1,1))
  1015.                                     {
  1016.                                         ResultCode[0] = RC_ERROR;
  1017.                                         ResultCode[1] = IoErr();
  1018.  
  1019.                                         break;
  1020.                                     }
  1021.                                 }
  1022.  
  1023.                                 if(!FWrite(SomeFile,"\n",1,1))
  1024.                                 {
  1025.                                     ResultCode[0] = RC_ERROR;
  1026.                                     ResultCode[1] = IoErr();
  1027.  
  1028.                                     break;
  1029.                                 }
  1030.                             }
  1031.  
  1032.                             Close(SomeFile);
  1033.  
  1034.                             AddProtection(FileName,FIBF_EXECUTE);
  1035.  
  1036.                             if(Config->MiscConfig->CreateIcons)
  1037.                                 AddIcon(FileName,FILETYPE_TEXT,TRUE);
  1038.                         }
  1039.                         else
  1040.                         {
  1041.                             ResultCode[0] = RC_ERROR;
  1042.                             ResultCode[1] = IoErr();
  1043.                         }
  1044.                     }
  1045.                     else
  1046.                     {
  1047.                         ResultCode[0] = RC_ERROR;
  1048.                         ResultCode[1] = TERMERROR_NO_DATA_TO_PROCESS;
  1049.                     }
  1050.  
  1051.                     break;
  1052.  
  1053.                 case DATATYPE_SCREENIMAGE:
  1054.  
  1055.                     if(!SaveWindow(FileName,Window))
  1056.                     {
  1057.                         ResultCode[0] = RC_ERROR;
  1058.                         ResultCode[1] = IoErr();
  1059.                     }
  1060.  
  1061.                     break;
  1062.             }
  1063.         }
  1064.         else
  1065.             ResultCode[0] = RC_WARN;
  1066.     }
  1067.  
  1068.     return(NULL);
  1069. }
  1070.  
  1071. STRPTR
  1072. RexxRemove(struct RexxPkt *Pkt)
  1073. {
  1074.     enum    {    ARG_REMOVE_FROM,ARG_REMOVE_NAME };
  1075.  
  1076.     LONG Index;
  1077.  
  1078.     if((Index = ToList(Args[ARG_REMOVE_FROM])) == -1)
  1079.     {
  1080.         ResultCode[0] = RC_ERROR;
  1081.         ResultCode[1] = TERMERROR_UNKNOWN_LIST;
  1082.     }
  1083.     else
  1084.     {
  1085.         if(Args[ARG_REMOVE_NAME] && Index == GLIST_DIAL)
  1086.         {
  1087.             ResultCode[0] = RC_ERROR;
  1088.             ResultCode[1] = TERMERROR_DATA_TYPES_INCOMPATIBLE;
  1089.         }
  1090.         else
  1091.         {
  1092.             struct GenericList *List;
  1093.  
  1094.             List = GenericListTable[Index];
  1095.  
  1096.             if(Args[ARG_REMOVE_NAME])
  1097.             {
  1098.                 STRPTR Buffer;
  1099.  
  1100.                 if(Buffer = CreateMatchBuffer(Args[ARG_REMOVE_NAME]))
  1101.                 {
  1102.                     struct Node *Node,*Next;
  1103.  
  1104.                     LockGenericList(List);
  1105.  
  1106.                     for(Node = (struct Node *)List->ListHeader.mlh_Head ; Next = Node->ln_Succ ; Node = Next)
  1107.                     {
  1108.                         if(MatchBuffer(Buffer,Node->ln_Name))
  1109.                         {
  1110.                             Forbid();
  1111.  
  1112.                             UnlockGenericList(List);
  1113.  
  1114.                             DeleteGenericListNode(List,Node,TRUE);
  1115.  
  1116.                             LockGenericList(List);
  1117.  
  1118.                             Permit();
  1119.                         }
  1120.                     }
  1121.  
  1122.                     UnlockGenericList(List);
  1123.  
  1124.                     DeleteMatchBuffer(Buffer);
  1125.                 }
  1126.                 else
  1127.                 {
  1128.                     ResultCode[0] = RC_ERROR;
  1129.                     ResultCode[1] = ERROR_NO_FREE_STORE;
  1130.                 }
  1131.             }
  1132.             else
  1133.                 DeleteGenericListNode(List,NULL,TRUE);
  1134.  
  1135.             if(!GenericListCount(List))
  1136.                 ResultCode[0] = RC_WARN;
  1137.         }
  1138.     }
  1139.  
  1140.     return(NULL);
  1141. }
  1142.  
  1143. STRPTR
  1144. RexxRequestFile(struct RexxPkt *Pkt)
  1145. {
  1146.     enum    {    ARG_REQUESTFILE_TITLE,ARG_REQUESTFILE_PATH,ARG_REQUESTFILE_FILE,
  1147.                 ARG_REQUESTFILE_PATTERN,ARG_REQUESTFILE_MULTI,ARG_REQUESTFILE_NAME
  1148.             };
  1149.  
  1150.     if(Args[ARG_REQUESTFILE_MULTI] && !Args[ARG_REQUESTFILE_NAME])
  1151.     {
  1152.         ResultCode[0] = RC_ERROR;
  1153.         ResultCode[1] = TERMERROR_RESULT_VARIABLE_REQUIRED;
  1154.     }
  1155.     else
  1156.     {
  1157.         UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  1158.         struct FileRequester *FileRequester;
  1159.  
  1160.         if(Args[ARG_REQUESTFILE_PATH])
  1161.         {
  1162.             LimitedStrcpy(sizeof(DummyBuffer),DummyBuffer,Args[ARG_REQUESTFILE_PATH]);
  1163.  
  1164.             if(Args[ARG_REQUESTFILE_FILE])
  1165.                 AddPart(DummyBuffer,Args[ARG_REQUESTFILE_FILE],sizeof(DummyBuffer));
  1166.         }
  1167.         else
  1168.         {
  1169.             if(Args[ARG_REQUESTFILE_FILE])
  1170.                 LimitedStrcpy(sizeof(DummyBuffer),DummyBuffer,Args[ARG_REQUESTFILE_FILE]);
  1171.             else
  1172.                 DummyBuffer[0] = 0;
  1173.         }
  1174.  
  1175.         BlockWindows();
  1176.  
  1177.         if(Args[ARG_REQUESTFILE_MULTI])
  1178.             FileRequester = OpenSeveralFiles(Window,Args[ARG_REQUESTFILE_TITLE],NULL,Args[ARG_REQUESTFILE_PATTERN],DummyBuffer,sizeof(DummyBuffer));
  1179.         else
  1180.             FileRequester = OpenSingleFile(Window,Args[ARG_REQUESTFILE_TITLE],NULL,Args[ARG_REQUESTFILE_PATTERN],DummyBuffer,sizeof(DummyBuffer));
  1181.  
  1182.         if(FileRequester)
  1183.         {
  1184.             if(Args[ARG_REQUESTFILE_NAME])
  1185.             {
  1186.                 if(Args[ARG_REQUESTFILE_MULTI])
  1187.                 {
  1188.                     struct WBArg *ArgList = FileRequester->fr_ArgList;
  1189.                     UBYTE LocalBuffer[MAX_FILENAME_LENGTH];
  1190.                     LONG i,Counted = 0;
  1191.  
  1192.                     for(i = 0 ; i < FileRequester->fr_NumArgs ; i++)
  1193.                     {
  1194.                         if(ArgList[i].wa_Name)
  1195.                         {
  1196.                             if(ArgList[i].wa_Lock)
  1197.                             {
  1198.                                 if(!NameFromLock(ArgList[i].wa_Lock,LocalBuffer,sizeof(LocalBuffer)))
  1199.                                 {
  1200.                                     ResultCode[0] = RC_ERROR;
  1201.                                     ResultCode[1] = IoErr();
  1202.  
  1203.                                     break;
  1204.                                 }
  1205.                             }
  1206.                             else
  1207.                                 strcpy(LocalBuffer,FileRequester->fr_Drawer);
  1208.  
  1209.                             if(AddPart(LocalBuffer,ArgList[i].wa_Name,sizeof(LocalBuffer)))
  1210.                             {
  1211.                                 if(CreateVarArgs(LocalBuffer,Pkt,"%s.%ld",Args[ARG_REQUESTFILE_NAME],i))
  1212.                                     Counted++;
  1213.                                 else
  1214.                                     break;
  1215.                             }
  1216.                             else
  1217.                             {
  1218.                                 ResultCode[0] = RC_ERROR;
  1219.                                 ResultCode[1] = IoErr();
  1220.  
  1221.                                 break;
  1222.                             }
  1223.                         }
  1224.                     }
  1225.  
  1226.                     if(Counted)
  1227.                     {
  1228.                         LimitedSPrintf(sizeof(LocalBuffer),LocalBuffer,"%ld",Counted);
  1229.  
  1230.                         CreateVarArgs(LocalBuffer,Pkt,"%s.COUNT",Args[ARG_REQUESTFILE_NAME]);
  1231.                     }
  1232.  
  1233.                     FreeAslRequest(FileRequester);
  1234.                 }
  1235.                 else
  1236.                 {
  1237.                     FreeAslRequest(FileRequester);
  1238.  
  1239.                     ReleaseWindows();
  1240.  
  1241.                     return(CreateVar(DummyBuffer,Pkt,Args[ARG_REQUESTFILE_NAME]));
  1242.                 }
  1243.             }
  1244.             else
  1245.             {
  1246.                 FreeAslRequest(FileRequester);
  1247.  
  1248.                 ReleaseWindows();
  1249.  
  1250.                 return(CreateResult(DummyBuffer,ResultCode));
  1251.             }
  1252.         }
  1253.         else
  1254.             ResultCode[0] = RC_WARN;
  1255.  
  1256.         ReleaseWindows();
  1257.     }
  1258.  
  1259.     return(NULL);
  1260. }
  1261.  
  1262. STRPTR
  1263. RexxReceiveFile(struct RexxPkt *Pkt)
  1264. {
  1265.     enum    {    ARG_RECEIVEFILE_MODE,ARG_RECEIVEFILE_NAME };
  1266.  
  1267.     LONG    Mode = TRANSFER_BINARY;
  1268.     STRPTR    Name = (STRPTR)Args[ARG_RECEIVEFILE_NAME];
  1269.  
  1270.     if(Args[ARG_RECEIVEFILE_MODE])
  1271.         Mode = ToMode(Args[ARG_RECEIVEFILE_MODE]);
  1272.  
  1273.     if(Mode == -1)
  1274.     {
  1275.         ResultCode[0] = RC_ERROR;
  1276.         ResultCode[1] = ERROR_ACTION_NOT_KNOWN;
  1277.     }
  1278.     else
  1279.     {
  1280.         BlockWindows();
  1281.  
  1282.         switch(Mode)
  1283.         {
  1284.             case TRANSFER_ASCII:
  1285.  
  1286.                 if(ChangeProtocol(Config->TransferConfig->ASCIIDownloadLibrary,Config->TransferConfig->ASCIIDownloadType))
  1287.                 {
  1288.                     StartReceiveXPR_File(TRANSFER_ASCII,Name,FALSE);
  1289.  
  1290.                     SerialCommand(Config->CommandConfig->DownloadMacro);
  1291.                 }
  1292.                 else
  1293.                 {
  1294.                     ResultCode[0] = RC_ERROR;
  1295.                     ResultCode[1] = ERROR_NO_FREE_STORE;
  1296.                 }
  1297.  
  1298.                 ResetProtocol();
  1299.  
  1300.                 break;
  1301.  
  1302.             case TRANSFER_TEXT:
  1303.  
  1304.                 if(ChangeProtocol(Config->TransferConfig->TextDownloadLibrary,Config->TransferConfig->TextDownloadType))
  1305.                 {
  1306.                     StartReceiveXPR_File(TRANSFER_TEXT,Name,FALSE);
  1307.  
  1308.                     SerialCommand(Config->CommandConfig->DownloadMacro);
  1309.                 }
  1310.                 else
  1311.                 {
  1312.                     ResultCode[0] = RC_ERROR;
  1313.                     ResultCode[1] = ERROR_NO_FREE_STORE;
  1314.                 }
  1315.  
  1316.                 ResetProtocol();
  1317.  
  1318.                 break;
  1319.  
  1320.             case TRANSFER_BINARY:
  1321.  
  1322.                 if(ChangeProtocol(Config->TransferConfig->BinaryDownloadLibrary,Config->TransferConfig->BinaryDownloadType))
  1323.                 {
  1324.                     StartReceiveXPR_File(TRANSFER_BINARY,Name,FALSE);
  1325.  
  1326.                     SerialCommand(Config->CommandConfig->DownloadMacro);
  1327.                 }
  1328.                 else
  1329.                 {
  1330.                     ResultCode[0] = RC_ERROR;
  1331.                     ResultCode[1] = ERROR_NO_FREE_STORE;
  1332.                 }
  1333.  
  1334.                 ResetProtocol();
  1335.  
  1336.                 break;
  1337.         }
  1338.  
  1339.         if(TransferFailed)
  1340.             ResultCode[0] = RC_ERROR;
  1341.         else
  1342.         {
  1343.             if(TransferAborted)
  1344.                 ResultCode[0] = RC_WARN;
  1345.         }
  1346.  
  1347.         ReleaseWindows();
  1348.     }
  1349.  
  1350.     return(NULL);
  1351. }
  1352.  
  1353. STRPTR
  1354. RexxPrint(struct RexxPkt *Pkt)
  1355. {
  1356.     enum    {    ARG_PRINT_FROM,ARG_PRINT_TO,ARG_PRINT_SERIAL,ARG_PRINT_MODEM,ARG_PRINT_SCREEN,
  1357.                 ARG_PRINT_TERMINAL,ARG_PRINT_USER,ARG_PRINT_COMMENT,ARG_PRINT_SIZE,
  1358.                 ARG_PRINT_DATE,ARG_PRINT_BITS
  1359.             };
  1360.  
  1361.     LONG    Index,Mode = -1;
  1362.     ULONG    Flags = NULL;
  1363.  
  1364.     if(Args[ARG_PRINT_SERIAL])
  1365.         Flags |= PRINT_SERIAL;
  1366.  
  1367.     if(Args[ARG_PRINT_MODEM])
  1368.         Flags |= PRINT_MODEM;
  1369.  
  1370.     if(Args[ARG_PRINT_SCREEN])
  1371.         Flags |= PRINT_SCREEN;
  1372.  
  1373.     if(Args[ARG_PRINT_TERMINAL])
  1374.         Flags |= PRINT_TERMINAL;
  1375.  
  1376.     if(Args[ARG_PRINT_USER])
  1377.         Flags |= PRINT_USERNAME;
  1378.  
  1379.     if(Args[ARG_PRINT_COMMENT])
  1380.         Flags |= PRINT_COMMENT;
  1381.  
  1382.     if(Args[ARG_PRINT_SIZE])
  1383.         Flags |= PRINT_SIZE;
  1384.  
  1385.     if(Args[ARG_PRINT_DATE])
  1386.         Flags |= PRINT_DATE;
  1387.  
  1388.     if(Args[ARG_PRINT_BITS])
  1389.         Flags |= PRINT_BITS;
  1390.  
  1391.     if((Index = ToList(Args[ARG_PRINT_FROM])) == -1)
  1392.     {
  1393.         if(!Stricmp(Args[ARG_PRINT_FROM],"SCREENTEXT"))
  1394.         {
  1395.             if(!RasterEnabled)
  1396.             {
  1397.                 ResultCode[0] = RC_ERROR;
  1398.                 ResultCode[1] = TERMERROR_NO_DATA_TO_PROCESS;
  1399.  
  1400.                 return(NULL);
  1401.             }
  1402.             else
  1403.                 Mode = 0;
  1404.         }
  1405.  
  1406.         if(!Stricmp(Args[ARG_PRINT_FROM],"CLIPBOARD"))
  1407.             Mode = 1;
  1408.  
  1409.         if(!Stricmp(Args[ARG_PRINT_FROM],"BUFFER"))
  1410.             Mode = 2;
  1411.     }
  1412.  
  1413.     if(Index == -1 && Mode == -1)
  1414.     {
  1415.         ResultCode[0] = RC_ERROR;
  1416.         ResultCode[1] = TERMERROR_UNKNOWN_LIST;
  1417.     }
  1418.     else
  1419.     {
  1420.         BOOL Continue = TRUE;
  1421.         LONG Error = 0;
  1422.         STRPTR Name;
  1423.         BPTR File;
  1424.  
  1425.         if(Args[ARG_PRINT_TO])
  1426.             Name = Args[ARG_PRINT_TO];
  1427.         else
  1428.             Name = "PRT:";
  1429.  
  1430.         if(File = Open(Name,MODE_NEWFILE))
  1431.         {
  1432.             struct Window *ReqWindow;
  1433.             struct EasyStruct Easy;
  1434.  
  1435.             Easy.es_StructSize        = sizeof(struct EasyStruct);
  1436.             Easy.es_Flags            = NULL;
  1437.             Easy.es_Title            = (UBYTE *)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  1438.             Easy.es_GadgetFormat    = (UBYTE *)LocaleString(MSG_PRINT_STOP_TXT);
  1439.             Easy.es_TextFormat        = (UBYTE *)LocaleString(MSG_GLOBAL_PRINTING_TXT);
  1440.  
  1441.             BlockWindows();
  1442.  
  1443.             if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  1444.             {
  1445.                 struct GenericList *List;
  1446.  
  1447.                 switch(Index)
  1448.                 {
  1449.                     case GLIST_DIAL:
  1450.  
  1451.                         List = GenericListTable[Index];
  1452.  
  1453.                         LockGenericList(List);
  1454.  
  1455.                         if(GenericListCount(List) > 0)
  1456.                         {
  1457.                             struct GenericDialNode *Node;
  1458.  
  1459.                             for(Node = (struct GenericDialNode *)List->ListHeader.mlh_Head ; Continue && Node->Node.ln_Succ ; Node = (struct GenericDialNode *)Node->Node.ln_Succ)
  1460.                             {
  1461.                                 if(!Node->Index)
  1462.                                     Continue = PrintText(File,ReqWindow,&Error,"\n\"???\" (%s)",Node->Node.ln_Name);
  1463.                             }
  1464.                         }
  1465.  
  1466.                         UnlockGenericList(List);
  1467.  
  1468.                         break;
  1469.  
  1470.                     case GLIST_UPLOAD:
  1471.                     case GLIST_DOWNLOAD:
  1472.  
  1473.                         List = GenericListTable[Index];
  1474.  
  1475.                         LockGenericList(List);
  1476.  
  1477.                         if(GenericListCount(List) > 0)
  1478.                         {
  1479.                             struct Node *TempNode;
  1480.  
  1481.                             for(TempNode = (struct Node *)List->ListHeader.mlh_Head ; Continue && TempNode->ln_Succ ; TempNode = TempNode->ln_Succ)
  1482.                                 Continue = PrintFileInformation(File,ReqWindow,&Error,TempNode->ln_Name,Flags);
  1483.                         }
  1484.  
  1485.                         UnlockGenericList(List);
  1486.  
  1487.                         break;
  1488.  
  1489.                     case GLIST_WAIT:
  1490.  
  1491.                         List = GenericListTable[Index];
  1492.  
  1493.                         LockGenericList(List);
  1494.  
  1495.                         if(GenericListCount(List) > 0)
  1496.                         {
  1497.                             struct Node *TempNode;
  1498.  
  1499.                             for(TempNode = (struct Node *)List->ListHeader.mlh_Head ; Continue && TempNode->ln_Succ ; TempNode = TempNode->ln_Succ)
  1500.                                 Continue = PrintText(File,ReqWindow,&Error,"%s\n",TempNode->ln_Name);
  1501.                         }
  1502.  
  1503.                         UnlockGenericList(List);
  1504.  
  1505.                         break;
  1506.  
  1507.                     default:
  1508.  
  1509.                         switch(Mode)
  1510.                         {
  1511.                             case 0:
  1512.  
  1513.                                 Continue = PrintScreen(File,ReqWindow,&Error);
  1514.                                 break;
  1515.  
  1516.                             case 1:
  1517.  
  1518.                                 Continue = PrintClip(File,ReqWindow,&Error);
  1519.                                 break;
  1520.  
  1521.                             case 2:
  1522.  
  1523.                                 Continue = PrintBuffer(File,ReqWindow,&Error);
  1524.                                 break;
  1525.                         }
  1526.  
  1527.                         break;
  1528.                 }
  1529.  
  1530.                 FreeSysRequest(ReqWindow);
  1531.             }
  1532.  
  1533.             ReleaseWindows();
  1534.  
  1535.             Close(File);
  1536.         }
  1537.         else
  1538.             Error = IoErr();
  1539.  
  1540.         if(Error)
  1541.         {
  1542.             ResultCode[0] = RC_ERROR;
  1543.             ResultCode[1] = Error;
  1544.         }
  1545.         else
  1546.         {
  1547.             if(!Continue)
  1548.                 ResultCode[0] = RC_WARN;
  1549.         }
  1550.     }
  1551.  
  1552.     return(NULL);
  1553. }
  1554.  
  1555. STRPTR
  1556. RexxOpenRequester(struct RexxPkt *Pkt)
  1557. {
  1558.     enum    {    ARG_OPENREQUESTER_REQUESTER };
  1559.  
  1560.     LONG Index;
  1561.  
  1562.     if((Index = ToRequester(Args[ARG_OPENREQUESTER_REQUESTER])) == -1)
  1563.     {
  1564.         ResultCode[0] = RC_ERROR;
  1565.         ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  1566.     }
  1567.     else
  1568.     {
  1569.         ULONG Code;
  1570.         LONG i;
  1571.  
  1572.         switch(Index)
  1573.         {
  1574.             case REQUESTER_SERIAL:
  1575.  
  1576.                 Code = MEN_SERIAL;
  1577.                 break;
  1578.  
  1579.             case REQUESTER_MODEM:
  1580.  
  1581.                 Code = MEN_MODEM;
  1582.                 break;
  1583.  
  1584.             case REQUESTER_SCREEN:
  1585.  
  1586.                 Code = MEN_SCREEN;
  1587.                 break;
  1588.  
  1589.             case REQUESTER_TERMINAL:
  1590.  
  1591.                 Code = MEN_TERMINAL;
  1592.                 break;
  1593.  
  1594.             case REQUESTER_EMULATION:
  1595.  
  1596.                 Code = MEN_SET_EMULATION;
  1597.                 break;
  1598.  
  1599.             case REQUESTER_CLIPBOARD:
  1600.  
  1601.                 Code = MEN_CLIPBOARD;
  1602.                 break;
  1603.  
  1604.             case REQUESTER_CAPTURE:
  1605.  
  1606.                 Code = MEN_CAPTURE;
  1607.                 break;
  1608.  
  1609.             case REQUESTER_COMMANDS:
  1610.  
  1611.                 Code = MEN_COMMANDS;
  1612.                 break;
  1613.  
  1614.             case REQUESTER_MISC:
  1615.  
  1616.                 Code = MEN_MISC;
  1617.                 break;
  1618.  
  1619.             case REQUESTER_PATH:
  1620.  
  1621.                 Code = MEN_PATH;
  1622.                 break;
  1623.  
  1624.             case REQUESTER_TRANSFER:
  1625.  
  1626.                 Code = MEN_TRANSFER;
  1627.                 break;
  1628.  
  1629.             case REQUESTER_TRANSLATIONS:
  1630.  
  1631.                 Code = MEN_TRANSLATION;
  1632.                 break;
  1633.  
  1634.             case REQUESTER_FUNCTIONKEYS:
  1635.  
  1636.                 Code = MEN_MACROS;
  1637.                 break;
  1638.  
  1639.             case REQUESTER_CURSORKEYS:
  1640.  
  1641.                 Code = MEN_CURSORKEYS;
  1642.                 break;
  1643.  
  1644.             case REQUESTER_FASTMACROS:
  1645.  
  1646.                 Code = MEN_FAST_MACROS;
  1647.                 break;
  1648.  
  1649.             case REQUESTER_HOTKEYS:
  1650.  
  1651.                 Code = MEN_HOTKEYS;
  1652.                 break;
  1653.  
  1654.             case REQUESTER_SPEECH:
  1655.  
  1656.                 Code = MEN_SPEECH;
  1657.                 break;
  1658.  
  1659.             case REQUESTER_SOUND:
  1660.  
  1661.                 Code = MEN_SOUND;
  1662.                 break;
  1663.  
  1664.  
  1665.             case REQUESTER_PHONE:
  1666.  
  1667.                 Code = MEN_PHONEBOOK;
  1668.                 break;
  1669.         }
  1670.  
  1671.             /* Scan the menu list... */
  1672.  
  1673.         for(i = 0 ; TermMenu[i].nm_Type != NM_END ; i++)
  1674.         {
  1675.                 /* Did we get a valid name string? */
  1676.  
  1677.             if(TermMenu[i].nm_Label != NM_BARLABEL && (TermMenu[i].nm_Type == NM_ITEM || TermMenu[i].nm_Type == NM_SUB))
  1678.             {
  1679.                 if((ULONG)TermMenu[i].nm_UserData == Code)
  1680.                 {
  1681.                     struct DataMsg *Msg;
  1682.  
  1683.                     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  1684.                     {
  1685.                         Msg->Type = DATAMSGTYPE_MENU;
  1686.                         Msg->Size = (ULONG)TermMenu[i].nm_UserData;
  1687.                         Msg->Data = NULL;
  1688.  
  1689.                         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  1690.  
  1691.                         ResultCode[0] = RC_OK;
  1692.                     }
  1693.                     else
  1694.                         ResultCode[0] = RC_WARN;
  1695.  
  1696.                     break;
  1697.                 }
  1698.             }
  1699.         }
  1700.     }
  1701.  
  1702.     return(NULL);
  1703. }
  1704.  
  1705. STRPTR
  1706. RexxOpen(struct RexxPkt *Pkt)
  1707. {
  1708.     enum    {    ARG_OPEN_NAME,ARG_OPEN_TO };
  1709.  
  1710.     LONG Index = ToConfig(Args[ARG_OPEN_TO]);
  1711.  
  1712.     if(Index == -1 || Index > DATATYPE_PHONEBOOK)
  1713.     {
  1714.         ResultCode[0] = RC_ERROR;
  1715.         ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  1716.     }
  1717.     else
  1718.     {
  1719.         UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  1720.         STRPTR FileName;
  1721.  
  1722.         if(Args[ARG_OPEN_NAME])
  1723.             FileName = Args[ARG_OPEN_NAME];
  1724.         else
  1725.         {
  1726.             struct FileRequester *FileRequest;
  1727.             LONG TitleID;
  1728.  
  1729.             FileName = NULL;
  1730.  
  1731.             switch(Index)
  1732.             {
  1733.                 case DATATYPE_TRANSLATIONS:
  1734.  
  1735.                     TitleID = MSG_PHONEPANEL_SELECT_TRANSLATION_TXT;
  1736.                     break;
  1737.  
  1738.                 case DATATYPE_FUNCTIONKEYS:
  1739.  
  1740.                     TitleID = MSG_PHONEPANEL_SELECT_KEYBOARD_MACROS_TXT;
  1741.                     break;
  1742.  
  1743.                 case DATATYPE_CURSORKEYS:
  1744.  
  1745.                     TitleID = MSG_PHONEPANEL_SELECT_CURSOR_KEYS_TXT;
  1746.                     break;
  1747.  
  1748.                 case DATATYPE_FASTMACROS:
  1749.  
  1750.                     TitleID = MSG_PHONEPANEL_SELECT_FAST_MACROS_TXT;
  1751.                     break;
  1752.  
  1753.                 case DATATYPE_HOTKEYS:
  1754.  
  1755.                     TitleID = MSG_HOTKEYPANEL_LOAD_HOTKEYS_TXT;
  1756.                     break;
  1757.  
  1758.                 case DATATYPE_SPEECH:
  1759.  
  1760.                     TitleID = MSG_SPEECHPANEL_LOAD_SPEECH_SETTINGS_TXT;
  1761.                     break;
  1762.  
  1763.                 case DATATYPE_SOUND:
  1764.  
  1765.                     TitleID = MSG_SOUNDPANEL_LOAD_SOUNDS_TXT;
  1766.                     break;
  1767.  
  1768.                 case DATATYPE_BUFFER:
  1769.  
  1770.                     TitleID = MSG_TERMMAIN_LOAD_BUFFER_TXT;
  1771.                     break;
  1772.  
  1773.                 case DATATYPE_CONFIGURATION:
  1774.  
  1775.                     TitleID = MSG_TERMMAIN_OPEN_PREFERENCES_TXT;
  1776.                     break;
  1777.  
  1778.                 case DATATYPE_PHONEBOOK:
  1779.  
  1780.                     TitleID = MSG_PHONEPANEL_LOAD_PHONEBOOK_TXT;
  1781.                     break;
  1782.             }
  1783.  
  1784.             BlockWindows();
  1785.  
  1786.             DummyBuffer[0] = 0;
  1787.  
  1788.             if(FileRequest = OpenSingleFile(Window,LocaleString(TitleID),NULL,NULL,DummyBuffer,sizeof(DummyBuffer)))
  1789.             {
  1790.                 FreeAslRequest(FileRequest);
  1791.  
  1792.                 FileName = DummyBuffer;
  1793.             }
  1794.             else
  1795.                 ResultCode[0] = RC_WARN;
  1796.  
  1797.             ReleaseWindows();
  1798.         }
  1799.  
  1800.         if(FileName)
  1801.         {
  1802.             struct TranslationEntry    **Send,**Receive;
  1803.             BPTR SomeFile;
  1804.             BOOL Success;
  1805.  
  1806.             if(!GetFileSize(FileName))
  1807.             {
  1808.                 ResultCode[0] = RC_ERROR;
  1809.                 ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  1810.  
  1811.                 return(NULL);
  1812.             }
  1813.  
  1814.             BlockWindows();
  1815.  
  1816.             switch(Index)
  1817.             {
  1818.                 case DATATYPE_TRANSLATIONS:
  1819.  
  1820.                     Receive = NULL;
  1821.                     Success = FALSE;
  1822.  
  1823.                     if(Send = AllocTranslationTable())
  1824.                     {
  1825.                         if(Receive = AllocTranslationTable())
  1826.                         {
  1827.                             if(!(Success = LoadTranslationTables(FileName,Send,Receive)))
  1828.                             {
  1829.                                 ResultCode[0] = RC_ERROR;
  1830.                                 ResultCode[1] = IoErr();
  1831.                             }
  1832.                         }
  1833.                         else
  1834.                         {
  1835.                             ResultCode[0] = RC_ERROR;
  1836.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  1837.                         }
  1838.                     }
  1839.                     else
  1840.                     {
  1841.                         ResultCode[0] = RC_ERROR;
  1842.                         ResultCode[1] = ERROR_NO_FREE_STORE;
  1843.                     }
  1844.  
  1845.                     if(!Success)
  1846.                     {
  1847.                         if(Send)
  1848.                             FreeTranslationTable(Send);
  1849.  
  1850.                         if(Receive)
  1851.                             FreeTranslationTable(Receive);
  1852.                     }
  1853.                     else
  1854.                     {
  1855.                         strcpy(Config->TranslationFileName,FileName);
  1856.  
  1857.                         strcpy(LastTranslation,FileName);
  1858.  
  1859.                         FreeTranslationTable(SendTable);
  1860.                         FreeTranslationTable(ReceiveTable);
  1861.  
  1862.                         SendTable        = Send;
  1863.                         ReceiveTable    = Receive;
  1864.                     }
  1865.  
  1866.                     break;
  1867.  
  1868.                 case DATATYPE_FUNCTIONKEYS:
  1869.  
  1870.                     if(!LoadMacros(FileName,MacroKeys))
  1871.                     {
  1872.                         ResultCode[0] = RC_ERROR;
  1873.                         ResultCode[1] = IoErr();
  1874.                     }
  1875.                     else
  1876.                     {
  1877.                         MacroChanged = FALSE;
  1878.  
  1879.                         strcpy(LastMacros,FileName);
  1880.  
  1881.                         strcpy(Config->MacroFileName,LastMacros);
  1882.                     }
  1883.  
  1884.                     break;
  1885.  
  1886.                 case DATATYPE_CURSORKEYS:
  1887.  
  1888.                     if(!ReadIFFData(FileName,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  1889.                     {
  1890.                         ResultCode[0] = RC_ERROR;
  1891.                         ResultCode[1] = IoErr();
  1892.                     }
  1893.                     else
  1894.                     {
  1895.                         CursorKeysChanged = FALSE;
  1896.  
  1897.                         strcpy(LastCursorKeys,FileName);
  1898.  
  1899.                         strcpy(Config->CursorFileName,LastCursorKeys);
  1900.                     }
  1901.  
  1902.                     break;
  1903.  
  1904.                 case DATATYPE_FASTMACROS:
  1905.  
  1906.                     if(!LoadFastMacros(FileName,&FastMacroList))
  1907.                     {
  1908.                         ResultCode[0] = RC_ERROR;
  1909.                         ResultCode[1] = IoErr();
  1910.                     }
  1911.                     else
  1912.                     {
  1913.                         strcpy(Config->FastMacroFileName,FileName);
  1914.  
  1915.                         strcpy(LastFastMacros,FileName);
  1916.  
  1917.                         FastMacrosChanged = FALSE;
  1918.  
  1919.                         FastMacroCount = GetListSize(&FastMacroList);
  1920.                     }
  1921.  
  1922.                     RefreshFastWindow();
  1923.  
  1924.                     break;
  1925.  
  1926.                 case DATATYPE_HOTKEYS:
  1927.  
  1928.                     if(!LoadHotkeys(FileName,&Hotkeys))
  1929.                     {
  1930.                         ResultCode[0] = RC_ERROR;
  1931.                         ResultCode[1] = IoErr();
  1932.                     }
  1933.                     else
  1934.                     {
  1935.                         strcpy(LastKeys,FileName);
  1936.                         strcpy(Config->HotkeyFileName,LastKeys);
  1937.  
  1938.                         HotkeysChanged = FALSE;
  1939.  
  1940.                         SetupCx();
  1941.                     }
  1942.  
  1943.                     break;
  1944.  
  1945.                 case DATATYPE_SPEECH:
  1946.  
  1947.                     if(!ReadIFFData(FileName,&SpeechConfig,sizeof(struct SpeechConfig),ID_SPEK))
  1948.                     {
  1949.                         ResultCode[0] = RC_ERROR;
  1950.                         ResultCode[1] = IoErr();
  1951.                     }
  1952.                     else
  1953.                     {
  1954.                         strcpy(LastSpeech,FileName);
  1955.                         strcpy(Config->SpeechFileName,LastSpeech);
  1956.  
  1957.                         SpeechSetup();
  1958.  
  1959.                         SpeechChanged = FALSE;
  1960.                     }
  1961.  
  1962.                     break;
  1963.  
  1964.                 case DATATYPE_SOUND:
  1965.  
  1966.                     if(!ReadIFFData(FileName,&SoundConfig,sizeof(struct SoundConfig),ID_SOUN))
  1967.                     {
  1968.                         ResultCode[0] = RC_ERROR;
  1969.                         ResultCode[1] = IoErr();
  1970.                     }
  1971.                     else
  1972.                     {
  1973.                         strcpy(LastSound,FileName);
  1974.                         strcpy(Config->SoundFileName,LastSound);
  1975.  
  1976.                         SoundInit();
  1977.  
  1978.                         SoundChanged = FALSE;
  1979.                     }
  1980.  
  1981.                     break;
  1982.  
  1983.                 case DATATYPE_BUFFER:
  1984.  
  1985.                     if(SomeFile = Open(FileName,MODE_OLDFILE))
  1986.                     {
  1987.                         LONG Len;
  1988.  
  1989.                         LineRead(NULL,NULL,NULL);
  1990.  
  1991.                         while((Len = LineRead(SomeFile,FileName,80)) > 0)
  1992.                             CaptureParser(ParserStuff,FileName,Len,(COPTR)AddLine);
  1993.  
  1994.                         Close(SomeFile);
  1995.  
  1996.                         BufferChanged = TRUE;
  1997.                     }
  1998.                     else
  1999.                     {
  2000.                         ResultCode[0] = RC_ERROR;
  2001.                         ResultCode[1] = IoErr();
  2002.                     }
  2003.  
  2004.                     break;
  2005.  
  2006.                 case DATATYPE_CONFIGURATION:
  2007.  
  2008.                     if(ReadConfig(FileName,PrivateConfig))
  2009.                     {
  2010.                         SwapConfig(PrivateConfig,Config);
  2011.  
  2012.                         strcpy(LastConfig,FileName);
  2013.  
  2014.                         ConfigSetup();
  2015.  
  2016.                         ConfigChanged = FALSE;
  2017.                     }
  2018.                     else
  2019.                     {
  2020.                         ResultCode[0] = RC_ERROR;
  2021.                         ResultCode[1] = IoErr();
  2022.                     }
  2023.  
  2024.                     break;
  2025.  
  2026.                 case DATATYPE_PHONEBOOK:
  2027.  
  2028.                     if(GetActiveEntry(GlobalPhoneHandle))
  2029.                     {
  2030.                         ResultCode[0] = RC_ERROR;
  2031.                         ResultCode[1] = ERROR_OBJECT_IN_USE;
  2032.                     }
  2033.                     else
  2034.                     {
  2035.                         PhonebookHandle *PhoneHandle;
  2036.  
  2037.                         if(PhoneHandle = LoadPhonebook(FileName))
  2038.                         {
  2039.                             strcpy(LastPhone,FileName);
  2040.                             strcpy(Config->PhonebookFileName,LastPhone);
  2041.  
  2042.                             PhonebookChanged = FALSE;
  2043.                             RebuildMenu = TRUE;
  2044.                             ActivateJob(MainJobQueue,RebuildMenuJob);
  2045.  
  2046.                             DeletePhonebook(GlobalPhoneHandle);
  2047.                             GlobalPhoneHandle = PhoneHandle;
  2048.                         }
  2049.                         else
  2050.                         {
  2051.                             ResultCode[0] = RC_ERROR;
  2052.                             ResultCode[1] = IoErr();
  2053.                         }
  2054.                     }
  2055.  
  2056.                     break;
  2057.             }
  2058.  
  2059.             ReleaseWindows();
  2060.         }
  2061.         else
  2062.             ResultCode[0] = RC_WARN;
  2063.     }
  2064.  
  2065.     return(NULL);
  2066. }
  2067.  
  2068. STRPTR
  2069. RexxDelay(struct RexxPkt *Pkt)
  2070. {
  2071.     enum    {    ARG_DELAY_MICROSECONDS,ARG_DELAY_SECONDS,ARG_DELAY_MINUTES,ARG_DELAY_QUIET };
  2072.  
  2073.     LONG Seconds,Micros;
  2074.     ULONG Signals;
  2075.     BOOL QuietPlease;
  2076.  
  2077.     Seconds = Micros = 0;
  2078.  
  2079.     if(Args[ARG_DELAY_QUIET] || !ReadRequest || !WriteRequest)
  2080.         QuietPlease = TRUE;
  2081.     else
  2082.         QuietPlease = FALSE;
  2083.  
  2084.     if(Args[ARG_DELAY_MINUTES])
  2085.         Seconds += 60 * (*(LONG *)Args[ARG_DELAY_MINUTES]);
  2086.  
  2087.     if(Args[ARG_DELAY_SECONDS])
  2088.         Seconds += *(LONG *)Args[ARG_DELAY_SECONDS];
  2089.  
  2090.     if(Args[ARG_DELAY_MICROSECONDS])
  2091.         Micros = *(LONG *)Args[ARG_DELAY_MICROSECONDS];
  2092.  
  2093.     if(Seconds || Micros)
  2094.     {
  2095.         BOOL Done;
  2096.  
  2097.         StartTime(Seconds,Micros);
  2098.  
  2099.         BlockWindows();
  2100.  
  2101.             /* Lock the current xOFF state and clear the xOFF flag. */
  2102.  
  2103.         Lock_xOFF();
  2104.         Clear_xOFF();
  2105.  
  2106.             /* Loop until the timer has elapsed. */
  2107.  
  2108.         Done = FALSE;
  2109.  
  2110.         do
  2111.         {
  2112.                 /* Wait for something to happen. */
  2113.  
  2114.             Signals = (*SerialWaitForData)(SIG_TIMER | SIG_BREAK);
  2115.  
  2116.             if(Signals & SIG_SERIAL)
  2117.             {
  2118.                 ULONG Length;
  2119.  
  2120.                     /* Check how much data is available. */
  2121.  
  2122.                 if(Length = (*SerialGetWaiting)())
  2123.                 {
  2124.                         /* Don't read more than the buffer will hold. */
  2125.  
  2126.                     if(Length > SerialBufferSize / 2)
  2127.                         Length = SerialBufferSize / 2;
  2128.  
  2129.                         /* Read the data. */
  2130.  
  2131.                     if(Length = (*SerialRead)(ReadBuffer,Length))
  2132.                     {
  2133.                             /* Got some more data. */
  2134.  
  2135.                         BytesIn += Length;
  2136.  
  2137.                         if(Translate_CR_LF)
  2138.                             Length = (*Translate_CR_LF)(ReadBuffer,Length);
  2139.  
  2140.                         if(!QuietPlease && Length)
  2141.                             ConProcess(ReadBuffer,Length);
  2142.                     }
  2143.                 }
  2144.             }
  2145.  
  2146.             if(Signals & SIG_BREAK)
  2147.             {
  2148.                 ResultCode[0] = RC_WARN;
  2149.  
  2150.                 Done = TRUE;
  2151.             }
  2152.  
  2153.             if(Signals & SIG_TIMER)
  2154.                 Done = TRUE;
  2155.         }
  2156.         while(!Done);
  2157.  
  2158.             /* Stop the timer. */
  2159.  
  2160.         StopTime();
  2161.  
  2162.             /* Unlock the xOFF state. */
  2163.  
  2164.         Unlock_xOFF();
  2165.  
  2166.         ReleaseWindows();
  2167.     }
  2168.  
  2169.     return(NULL);
  2170. }
  2171.  
  2172. STRPTR
  2173. RexxCapture(struct RexxPkt *Pkt)
  2174. {
  2175.     enum    {    ARG_CAPTURE_TO,ARG_CAPTURE_NAME,ARG_OVERWRITE,ARG_APPEND,ARG_SKIP };
  2176.  
  2177.     if(!Stricmp(Args[ARG_CAPTURE_TO],"PRINTER"))
  2178.     {
  2179.         if(!PrinterCapture)
  2180.             OpenPrinterCapture(FALSE);
  2181.     }
  2182.     else
  2183.     {
  2184.         if(!Stricmp(Args[ARG_CAPTURE_TO],"FILE"))
  2185.         {
  2186.             if(FileCapture)
  2187.             {
  2188.                 ResultCode[0] = RC_ERROR;
  2189.                 ResultCode[1] = ERROR_OBJECT_IN_USE;
  2190.             }
  2191.             else
  2192.             {
  2193.                 if(Args[ARG_CAPTURE_NAME])
  2194.                 {
  2195.                     if(FileCapture = BufferOpen(Args[ARG_CAPTURE_NAME],"a"))
  2196.                         strcpy(CaptureName,Args[ARG_CAPTURE_NAME]);
  2197.                     else
  2198.                     {
  2199.                         ResultCode[0] = RC_ERROR;
  2200.                         ResultCode[1] = IoErr();
  2201.                     }
  2202.                 }
  2203.                 else
  2204.                 {
  2205.                     UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  2206.                     struct FileRequester *FileRequest;
  2207.  
  2208.                     if(!CaptureName[0])
  2209.                     {
  2210.                         strcpy(CaptureName,Config->CaptureConfig->CapturePath);
  2211.  
  2212.                         if(!AddPart(CaptureName,LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT),sizeof(DummyBuffer)))
  2213.                             CaptureName[0] = 0;
  2214.                     }
  2215.  
  2216.                     strcpy(DummyBuffer,CaptureName);
  2217.  
  2218.                     BlockWindows();
  2219.  
  2220.                     if(FileRequest = SaveFileOverwrite(Window,LocaleString(MSG_TERMMAIN_CAPTURE_TO_DISK_TXT),LocaleString(MSG_GLOBAL_OPEN_TXT),NULL,DummyBuffer,sizeof(DummyBuffer)))
  2221.                     {
  2222.                         BOOL Continue;
  2223.  
  2224.                         if(GetFileSize(DummyBuffer))
  2225.                         {
  2226.                             Continue = TRUE;
  2227.  
  2228.                             if(!Args[ARG_OVERWRITE] && ! Args[ARG_APPEND] && ! Args[ARG_SKIP])
  2229.                             {
  2230.                                 switch(ShowRequest(Window,LocaleString(MSG_GLOBAL_FILE_ALREADY_EXISTS_TXT),LocaleString(MSG_GLOBAL_CREATE_APPEND_CANCEL_TXT),DummyBuffer))
  2231.                                 {
  2232.                                     case 0:
  2233.  
  2234.                                         ResultCode[0] = RC_WARN;
  2235.                                         Continue = FALSE;
  2236.                                         break;
  2237.  
  2238.                                     case 1:
  2239.  
  2240.                                         FileCapture = BufferOpen(DummyBuffer,"w");
  2241.                                         break;
  2242.  
  2243.                                     case 2:
  2244.  
  2245.                                         FileCapture = BufferOpen(DummyBuffer,"a");
  2246.                                         break;
  2247.                                 }
  2248.                             }
  2249.                             else
  2250.                             {
  2251.                                 STRPTR Mode;
  2252.  
  2253.                                 if(Args[ARG_OVERWRITE])
  2254.                                     Mode = "w";
  2255.                                 else if(Args[ARG_APPEND])
  2256.                                     Mode = "a";
  2257.                                 else
  2258.                                     Mode = NULL;
  2259.  
  2260.                                 if(Mode)
  2261.                                     FileCapture = BufferOpen(DummyBuffer,Mode);
  2262.                                 else
  2263.                                 {
  2264.                                     ResultCode[0] = RC_WARN;
  2265.                                     Continue = FALSE;
  2266.                                 }
  2267.                             }
  2268.                         }
  2269.                         else
  2270.                         {
  2271.                             Continue = TRUE;
  2272.  
  2273.                             FileCapture = BufferOpen(DummyBuffer,"w");
  2274.                         }
  2275.  
  2276.                         if(Continue)
  2277.                         {
  2278.                             if(!FileCapture)
  2279.                             {
  2280.                                 ShowRequest(Window,LocaleString(MSG_GLOBAL_ERROR_OPENING_FILE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  2281.  
  2282.                                 ResultCode[0] = RC_ERROR;
  2283.                                 ResultCode[1] = IoErr();
  2284.                             }
  2285.                             else
  2286.                             {
  2287.                                 strcpy(CaptureName,DummyBuffer);
  2288.  
  2289.                                 CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  2290.                             }
  2291.                         }
  2292.  
  2293.                         FreeAslRequest(FileRequest);
  2294.                     }
  2295.  
  2296.                     ReleaseWindows();
  2297.                 }
  2298.             }
  2299.         }
  2300.         else
  2301.         {
  2302.             ResultCode[0] = RC_ERROR;
  2303.             ResultCode[1] = ERROR_REQUIRED_ARG_MISSING;
  2304.         }
  2305.     }
  2306.  
  2307.     ConOutputUpdate();
  2308.  
  2309.     CheckItem(MEN_CAPTURE_TO_FILE,        FileCapture != NULL);
  2310.     CheckItem(MEN_CAPTURE_TO_PRINTER,    PrinterCapture != NULL);
  2311.  
  2312.     return(NULL);
  2313. }
  2314.  
  2315. STRPTR
  2316. RexxAdd(struct RexxPkt *Pkt)
  2317. {
  2318.     enum    {    ARG_ADD_FROM,ARG_ADD_BEFORE,ARG_ADD_AFTER,ARG_ADD_RESPONSE,
  2319.                 ARG_ADD_COMMAND,ARG_ADD_PHONEENTRY,ARG_ADD_NAME
  2320.             };
  2321.  
  2322.     LONG ListIndex;
  2323.  
  2324.     if((ListIndex = ToList(Args[ARG_ADD_FROM])) != -1)
  2325.     {
  2326.         struct GenericList *List = GenericListTable[ListIndex];
  2327.         LONG AddMode;
  2328.  
  2329.         if(Args[ARG_ADD_BEFORE])
  2330.             AddMode = ADD_GLIST_BEFORE;
  2331.         else
  2332.         {
  2333.             if(Args[ARG_ADD_AFTER])
  2334.                 AddMode = ADD_GLIST_BEHIND;
  2335.             else
  2336.                 AddMode = ADD_GLIST_BOTTOM;
  2337.         }
  2338.  
  2339.         if(ListIndex == GLIST_DIAL)
  2340.         {
  2341.             if(Args[ARG_ADD_PHONEENTRY])
  2342.             {
  2343.                 if(!IsNumeric(Args[ARG_ADD_PHONEENTRY]))
  2344.                 {
  2345.                     STRPTR Buffer;
  2346.  
  2347.                     if(Buffer = CreateMatchBuffer(Args[ARG_ADD_PHONEENTRY]))
  2348.                     {
  2349.                         struct GenericDialNode *Node;
  2350.                         BOOL GotIt = FALSE;
  2351.                         LONG i;
  2352.  
  2353.                         for(i = 0 ; i < GlobalPhoneHandle->NumPhoneEntries ; i++)
  2354.                         {
  2355.                             if(MatchBuffer(Buffer,GlobalPhoneHandle->Phonebook[i]->Header->Name))
  2356.                             {
  2357.                                 if(Node = (struct GenericDialNode *)CreateGenericListNode(sizeof(struct GenericDialNode),GlobalPhoneHandle->Phonebook[i]->Header->Name))
  2358.                                 {
  2359.                                     Node->Number = NULL;
  2360.                                     Node->Index = -1;
  2361.  
  2362.                                     AddGenericListNode(List,(struct Node *)Node,AddMode,TRUE);
  2363.  
  2364.                                     GotIt = TRUE;
  2365.                                 }
  2366.                                 else
  2367.                                 {
  2368.                                     ResultCode[0] = RC_ERROR;
  2369.                                     ResultCode[1] = ERROR_NO_FREE_STORE;
  2370.  
  2371.                                     break;
  2372.                                 }
  2373.                             }
  2374.                         }
  2375.  
  2376.                         if(!GotIt && ResultCode[0] != RC_ERROR)
  2377.                         {
  2378.                             ResultCode[0] = RC_ERROR;
  2379.                             ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  2380.                         }
  2381.  
  2382.                         DeleteMatchBuffer(Buffer);
  2383.                     }
  2384.                     else
  2385.                     {
  2386.                         ResultCode[0] = RC_ERROR;
  2387.                         ResultCode[1] = ERROR_NO_FREE_STORE;
  2388.                     }
  2389.                 }
  2390.                 else
  2391.                 {
  2392.                     LONG Index = Atol(Args[ARG_ADD_PHONEENTRY]);
  2393.  
  2394.                     if(Index < 0 || Index > GlobalPhoneHandle->NumPhoneEntries)
  2395.                     {
  2396.                         ResultCode[0] = RC_ERROR;
  2397.                         ResultCode[1] = TERMERROR_INDEX_OUT_OF_RANGE;
  2398.                     }
  2399.                     else
  2400.                     {
  2401.                         struct GenericDialNode *Node;
  2402.  
  2403.                         if(Node = (struct GenericDialNode *)CreateGenericListNode(sizeof(struct GenericDialNode),GlobalPhoneHandle->Phonebook[Index]->Header->Name))
  2404.                         {
  2405.                             Node->Number = NULL;
  2406.                             Node->Index = Index;
  2407.  
  2408.                             AddGenericListNode(List,(struct Node *)Node,AddMode,TRUE);
  2409.                         }
  2410.                         else
  2411.                         {
  2412.                             ResultCode[0] = RC_ERROR;
  2413.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  2414.                         }
  2415.                     }
  2416.                 }
  2417.             }
  2418.             else
  2419.             {
  2420.                 if(Args[ARG_ADD_NAME])
  2421.                 {
  2422.                     struct GenericDialNode *Node;
  2423.  
  2424.                     if(Node = (struct GenericDialNode *)CreateGenericListNode(sizeof(struct GenericDialNode),Args[ARG_ADD_NAME]))
  2425.                     {
  2426.                         Node->Number = Node->Node.ln_Name;
  2427.                         Node->Index = -1;
  2428.  
  2429.                         AddGenericListNode(List,(struct Node *)Node,AddMode,TRUE);
  2430.                     }
  2431.                     else
  2432.                     {
  2433.                         ResultCode[0] = RC_ERROR;
  2434.                         ResultCode[1] = ERROR_NO_FREE_STORE;
  2435.                     }
  2436.                 }
  2437.             }
  2438.         }
  2439.         else
  2440.         {
  2441.             if(ListIndex == GLIST_WAIT)
  2442.             {
  2443.                 STRPTR    Response;
  2444.                 LONG    ResponseLen;
  2445.  
  2446.                 if(Args[ARG_ADD_RESPONSE])
  2447.                 {
  2448.                     Response    = Args[ARG_ADD_RESPONSE];
  2449.                     ResponseLen    = strlen(Response);
  2450.                 }
  2451.                 else
  2452.                 {
  2453.                     Response    = NULL;
  2454.                     ResponseLen    = 0;
  2455.                 }
  2456.  
  2457.                 if(Args[ARG_ADD_NAME])
  2458.                 {
  2459.                     struct WaitNode *Node;
  2460.  
  2461.                     if(Node = (struct WaitNode *)CreateGenericListNode(sizeof(struct WaitNode) + ResponseLen + 1,Args[ARG_ADD_NAME]))
  2462.                     {
  2463.                         LONG i,Len;
  2464.  
  2465.                         Len = TranslateString(Node->Node.ln_Name,Node->Node.ln_Name);
  2466.  
  2467.                         Node->Node.ln_Name[Len] = 0;
  2468.  
  2469.                         for(i = 0 ; i < Len ; i++)
  2470.                             Node->Node.ln_Name[i] = ToUpper(Node->Node.ln_Name[i]);
  2471.  
  2472.                         if(Response && ResponseLen)
  2473.                         {
  2474.                             Node->Response = &Node->Node.ln_Name[Len + 1];
  2475.  
  2476.                             strcpy(Node->Response,Response);
  2477.  
  2478.                             Node->ResponseLen = TranslateString(Node->Response,Node->Response);
  2479.                         }
  2480.                         else
  2481.                             Node->ResponseLen = 0;
  2482.  
  2483.                         AddGenericListNode(List,(struct Node *)Node,AddMode,TRUE);
  2484.                     }
  2485.                     else
  2486.                     {
  2487.                         ResultCode[0] = RC_ERROR;
  2488.                         ResultCode[1] = ERROR_NO_FREE_STORE;
  2489.                     }
  2490.                 }
  2491.                 else
  2492.                 {
  2493.                     ResultCode[0] = RC_ERROR;
  2494.                     ResultCode[1] = ERROR_REQUIRED_ARG_MISSING;
  2495.                 }
  2496.             }
  2497.             else
  2498.             {
  2499.                 if(ListIndex == GLIST_TRAP)
  2500.                 {
  2501.                     if(!Args[ARG_ADD_NAME] || !Args[ARG_ADD_COMMAND])
  2502.                     {
  2503.                         struct TrapNode    *Node;
  2504.                         UBYTE LocalBuffer[MAX_FILENAME_LENGTH];
  2505.                         LONG NameLen;
  2506.  
  2507.                         if(strlen(Args[ARG_ADD_NAME]) > sizeof(LocalBuffer) - 1)
  2508.                             Args[ARG_ADD_NAME][sizeof(LocalBuffer) - 1] = 0;
  2509.  
  2510.                         NameLen = TranslateString(Args[ARG_ADD_NAME],LocalBuffer);
  2511.  
  2512.                         if(Node = (struct TrapNode *)AllocVecPooled(sizeof(struct TrapNode) + strlen(Args[ARG_ADD_NAME]) + 1 + NameLen + strlen(Args[ARG_ADD_COMMAND]) + 1,MEMF_ANY))
  2513.                         {
  2514.                             STRPTR String = Node->Node.ln_Name = (STRPTR)(Node + 1);
  2515.  
  2516.                             strcpy(String,Args[ARG_ADD_NAME]);
  2517.  
  2518.                             String += strlen(String) + 1;
  2519.  
  2520.                             Node->Sequence = String;
  2521.  
  2522.                             CopyMem(LocalBuffer,String,NameLen);
  2523.  
  2524.                             String += NameLen;
  2525.  
  2526.                             Node->Command = String;
  2527.  
  2528.                             strcpy(String,Args[ARG_ADD_COMMAND]);
  2529.  
  2530.                             Node->SequenceLen = NameLen;
  2531.                             Node->Count = 0;
  2532.  
  2533.                             AddGenericListNode(List,(struct Node *)Node,AddMode,TRUE);
  2534.                         }
  2535.                         else
  2536.                         {
  2537.                             ResultCode[0] = RC_ERROR;
  2538.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  2539.                         }
  2540.                     }
  2541.                     else
  2542.                     {
  2543.                         ResultCode[0] = RC_ERROR;
  2544.                         ResultCode[1] = ERROR_REQUIRED_ARG_MISSING;
  2545.                     }
  2546.                 }
  2547.                 else
  2548.                 {
  2549.                     if(Args[ARG_ADD_NAME])
  2550.                     {
  2551.                         struct Node *Node;
  2552.  
  2553.                         if(Node = CreateGenericListNode(sizeof(struct DialNode),Args[ARG_ADD_NAME]))
  2554.                             AddGenericListNode(List,Node,AddMode,TRUE);
  2555.                         else
  2556.                         {
  2557.                             ResultCode[0] = RC_ERROR;
  2558.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  2559.                         }
  2560.                     }
  2561.                     else
  2562.                     {
  2563.                         ResultCode[0] = RC_ERROR;
  2564.                         ResultCode[1] = TERMERROR_WRONG_LIST;
  2565.                     }
  2566.                 }
  2567.             }
  2568.         }
  2569.     }
  2570.     else
  2571.     {
  2572.         ResultCode[0] = RC_ERROR;
  2573.         ResultCode[1] = TERMERROR_UNKNOWN_LIST;
  2574.     }
  2575.  
  2576.     return(NULL);
  2577. }
  2578.  
  2579. STRPTR
  2580. RexxActivate(struct RexxPkt *UnusedPkt)
  2581. {
  2582.     if(Window)
  2583.         BumpWindow(Window);
  2584.     else
  2585.         Signal((struct Task *)ThisProcess,SIGBREAKF_CTRL_F);
  2586.  
  2587.     return(NULL);
  2588. }
  2589.  
  2590. STRPTR
  2591. RexxBaud(struct RexxPkt *Pkt)
  2592. {
  2593.     enum    {    ARG_BAUD_RATE };
  2594.  
  2595.     LONG Rate = *(LONG *)Args[ARG_BAUD_RATE],Min = MILLION,Diff,Index;
  2596.     UBYTE Number[10];
  2597.     LONG i;
  2598.  
  2599.     for(i = 0 ; i < NumBaudRates ; i++)
  2600.     {
  2601.         Diff = Rate - BaudRates[i];
  2602.  
  2603.         if(Diff >= 0 && Diff < Min)
  2604.         {
  2605.             Min        = Diff;
  2606.             Index    = i;
  2607.         }
  2608.     }
  2609.  
  2610.     LimitedSPrintf(sizeof(Number),Number,"%ld");
  2611.  
  2612.     if(BaudRates[Index] != Config->SerialConfig->BaudRate)
  2613.     {
  2614.         Config->SerialConfig->BaudRate = BaudRates[Index];
  2615.  
  2616.         ConfigChanged = TRUE;
  2617.  
  2618.         UpdateRequired = TRUE;
  2619.     }
  2620.  
  2621.     return(CreateArgstring(Number,strlen(Number)));
  2622. }
  2623.  
  2624. STRPTR
  2625. RexxBeepScreen(struct RexxPkt *UnusedPkt)
  2626. {
  2627.     BellSignal();
  2628.  
  2629.     return(NULL);
  2630. }
  2631.  
  2632. STRPTR
  2633. RexxCallMenu(struct RexxPkt *Pkt)
  2634. {
  2635.     enum    {    ARG_CALLMENU_TITLE };
  2636.  
  2637.     STRPTR Buffer;
  2638.  
  2639.     if(Buffer = CreateMatchBuffer(Args[ARG_CALLMENU_TITLE]))
  2640.     {
  2641.         LONG i;
  2642.  
  2643.         ResultCode[0] = RC_WARN;
  2644.  
  2645.             /* Scan the menu list... */
  2646.  
  2647.         for(i = 0 ; TermMenu[i].nm_Type != NM_END ; i++)
  2648.         {
  2649.                 /* Did we get a valid name string? */
  2650.  
  2651.             if(TermMenu[i].nm_Label != NM_BARLABEL && (TermMenu[i].nm_Type == NM_ITEM || TermMenu[i].nm_Type == NM_SUB))
  2652.             {
  2653.                     /* Does the name match our template? */
  2654.  
  2655.                 if(MatchBuffer(Buffer,TermMenu[i].nm_Label))
  2656.                 {
  2657.                     struct DataMsg *Msg;
  2658.  
  2659.                     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  2660.                     {
  2661.                         Msg->Type = DATAMSGTYPE_MENU;
  2662.                         Msg->Size = (ULONG)TermMenu[i].nm_UserData;
  2663.                         Msg->Data = NULL;
  2664.  
  2665.                         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  2666.  
  2667.                         ResultCode[0] = RC_OK;
  2668.                     }
  2669.                     else
  2670.                         ResultCode[0] = RC_WARN;
  2671.  
  2672.                     break;
  2673.                 }
  2674.             }
  2675.         }
  2676.  
  2677.         DeleteMatchBuffer(Buffer);
  2678.     }
  2679.     else
  2680.     {
  2681.         ResultCode[0] = RC_ERROR;
  2682.         ResultCode[1] = ERROR_NO_FREE_STORE;
  2683.     }
  2684.  
  2685.     return(NULL);
  2686. }
  2687.  
  2688. STRPTR
  2689. RexxClear(struct RexxPkt *Pkt)
  2690. {
  2691.     enum    {    ARG_CLEAR_FROM,ARG_CLEAR_FORCE };
  2692.  
  2693.     if(!Stricmp(Args[ARG_CLEAR_FROM],"BUFFER"))
  2694.     {
  2695.         if(Lines)
  2696.         {
  2697.             if(Args[ARG_CLEAR_FORCE])
  2698.             {
  2699.                 FreeBuffer();
  2700.  
  2701.                 TerminateBuffer();
  2702.             }
  2703.             else
  2704.             {
  2705.                 BlockWindows();
  2706.  
  2707.                 if(ShowRequest(Window,LocaleString(MSG_TERMMAIN_BUFFER_STILL_HOLDS_LINES_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT),Lines))
  2708.                 {
  2709.                     FreeBuffer();
  2710.  
  2711.                     TerminateBuffer();
  2712.                 }
  2713.                 else
  2714.                     ResultCode[0] = RC_WARN;
  2715.  
  2716.                 ReleaseWindows();
  2717.             }
  2718.         }
  2719.     }
  2720.     else
  2721.     {
  2722.         LONG ListIndex;
  2723.  
  2724.         if((ListIndex = ToList(Args[ARG_CLEAR_FROM])) != -1)
  2725.             ClearGenericList(GenericListTable[ListIndex],TRUE);
  2726.         else
  2727.         {
  2728.             ResultCode[0] = RC_ERROR;
  2729.             ResultCode[1] = TERMERROR_UNKNOWN_LIST;
  2730.         }
  2731.     }
  2732.  
  2733.     return(NULL);
  2734. }
  2735.  
  2736. STRPTR
  2737. RexxClearScreen(struct RexxPkt *UnusedPkt)
  2738. {
  2739.     ConClear();
  2740.  
  2741.     return(NULL);
  2742. }
  2743.  
  2744. STRPTR
  2745. RexxClose(struct RexxPkt *Pkt)
  2746. {
  2747.     enum    {    ARG_CLOSE_FROM };
  2748.  
  2749.     STATIC STRPTR ValidArgs[3] =
  2750.     {
  2751.         "PRINTER",
  2752.         "FILE",
  2753.         "ALL"
  2754.     };
  2755.  
  2756.     LONG i;
  2757.  
  2758.     for(i = 0 ; i < 3 ; i++)
  2759.     {
  2760.         if(!Stricmp(Args[ARG_CLOSE_FROM],ValidArgs[i]))
  2761.         {
  2762.             if(i == 0 || i == 2)
  2763.             {
  2764.                 if(PrinterCapture)
  2765.                     ClosePrinterCapture(TRUE);
  2766.             }
  2767.  
  2768.             if(i == 1 || i == 2)
  2769.             {
  2770.                 if(FileCapture)
  2771.                 {
  2772.                     BufferClose(FileCapture);
  2773.  
  2774.                     CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  2775.  
  2776.                     FileCapture = NULL;
  2777.  
  2778.                     if(!GetFileSize(CaptureName))
  2779.                         DeleteFile(CaptureName);
  2780.                     else
  2781.                     {
  2782.                         AddProtection(CaptureName,FIBF_EXECUTE);
  2783.  
  2784.                         if(Config->MiscConfig->CreateIcons)
  2785.                             AddIcon(CaptureName,FILETYPE_TEXT,TRUE);
  2786.                     }
  2787.  
  2788.                     ConOutputUpdate();
  2789.                 }
  2790.             }
  2791.  
  2792.             return(NULL);
  2793.         }
  2794.     }
  2795.  
  2796.     ResultCode[0] = RC_ERROR;
  2797.     ResultCode[1] = ERROR_TOO_MANY_ARGS;
  2798.  
  2799.     return(NULL);
  2800. }
  2801.  
  2802. STRPTR
  2803. RexxCloseDevice(struct RexxPkt *UnusedPkt)
  2804. {
  2805.     ClearSerial();
  2806.  
  2807.     DeleteSerial();
  2808.  
  2809.     return(NULL);
  2810. }
  2811.  
  2812. STRPTR
  2813. RexxCloseRequester(struct RexxPkt *Pkt)
  2814. {
  2815.     if(ThisProcess)
  2816.         Signal((struct Task *)ThisProcess,SIG_BREAK);
  2817.     else
  2818.         ResultCode[0] = RC_WARN;
  2819.  
  2820.     return(NULL);
  2821. }
  2822.  
  2823. STRPTR
  2824. RexxDeactivate(struct RexxPkt *UnusedPkt)
  2825. {
  2826.     Forbid();
  2827.  
  2828.     if(Window)
  2829.         ActivateJob(MainJobQueue,IconifyJob);
  2830.  
  2831.     Permit();
  2832.  
  2833.     return(NULL);
  2834. }
  2835.  
  2836. STATIC VOID
  2837. RexxDialDestructor(struct MsgItem *Item)
  2838. {
  2839.     if(((struct DataDialMsg *)Item)->DialMsg)
  2840.     {
  2841.         ((struct DataDialMsg *)Item)->DialMsg->rm_Result1 = RC_WARN;
  2842.         ((struct DataDialMsg *)Item)->DialMsg->rm_Result2 = 0;
  2843.  
  2844.         ReplyMsg((struct Message *)((struct DataDialMsg *)Item)->DialMsg);
  2845.     }
  2846.  
  2847.     DeleteList(((struct DataDialMsg *)Item)->DialList);
  2848.  
  2849.     FreeVecPooled(Item);
  2850. }
  2851.  
  2852. STRPTR
  2853. RexxDial(struct RexxPkt *Pkt)
  2854. {
  2855.     enum    {    ARG_SYNC,ARG_DIAL_NUM };
  2856.  
  2857.     struct DataDialMsg *Msg;
  2858.     struct List *DialList;
  2859.  
  2860.     if(!(Msg = (struct DataDialMsg *)CreateMsgItem(sizeof(struct DataDialMsg))))
  2861.     {
  2862.         ResultCode[0] = RC_ERROR;
  2863.         ResultCode[1] = ERROR_NO_FREE_STORE;
  2864.  
  2865.         return(NULL);
  2866.     }
  2867.  
  2868.     if(Args[ARG_DIAL_NUM])
  2869.     {
  2870.         if(DialList = CreateList())
  2871.         {
  2872.             struct GenericDialNode *Node;
  2873.             LONG Len;
  2874.  
  2875.             Len = strlen(Args[ARG_DIAL_NUM]);
  2876.  
  2877.             if(Node = (struct GenericDialNode *)AllocVecPooled(sizeof(struct DialNode) + Len + 1,MEMF_ANY | MEMF_CLEAR))
  2878.             {
  2879.                 Node->Node.ln_Name = (STRPTR)(Node + 1);
  2880.  
  2881.                 strcpy(Node->Node.ln_Name,Args[ARG_DIAL_NUM]);
  2882.  
  2883.                 Node->Number = Node->Node.ln_Name;
  2884.                 Node->Index = -1;
  2885.  
  2886.                 AddTail(DialList,(struct Node *)Node);
  2887.             }
  2888.             else
  2889.             {
  2890.                 DeleteMsgItem((struct MsgItem *)Msg);
  2891.                 FreeVecPooled(DialList);
  2892.  
  2893.                 ResultCode[0] = RC_ERROR;
  2894.                 ResultCode[1] = ERROR_NO_FREE_STORE;
  2895.  
  2896.                 return(NULL);
  2897.             }
  2898.         }
  2899.         else
  2900.         {
  2901.             DeleteMsgItem((struct MsgItem *)Msg);
  2902.             ResultCode[0] = RC_ERROR;
  2903.             ResultCode[1] = ERROR_NO_FREE_STORE;
  2904.  
  2905.             return(NULL);
  2906.         }
  2907.     }
  2908.     else
  2909.     {
  2910.         if(GenericListCount(GenericListTable[GLIST_DIAL]) > 0)
  2911.         {
  2912.             if(DialList = CreateList())
  2913.             {
  2914.                 struct Node *Node;
  2915.  
  2916.                 while(Node = RemoveFirstGenericListNode(GenericListTable[GLIST_DIAL]))
  2917.                     AddTail(DialList,Node);
  2918.             }
  2919.             else
  2920.             {
  2921.                 DeleteMsgItem((struct MsgItem *)Msg);
  2922.  
  2923.                 ResultCode[0] = RC_ERROR;
  2924.                 ResultCode[1] = ERROR_NO_FREE_STORE;
  2925.  
  2926.                 return(NULL);
  2927.             }
  2928.         }
  2929.         else
  2930.             DialList = NULL;
  2931.     }
  2932.  
  2933.     if(DialList)
  2934.     {
  2935.         if(Args[ARG_SYNC])
  2936.         {
  2937.             Msg->DialMsg = Pkt->RexxMsg;
  2938.  
  2939.             Pkt->RexxMsg = NULL;
  2940.         }
  2941.         else
  2942.             Msg->DialMsg = NULL;
  2943.  
  2944.         InitMsgItem(Msg,RexxDialDestructor);
  2945.  
  2946.         Msg->Data.Type = DATAMSGTYPE_DIAL;
  2947.         Msg->DialList = DialList;
  2948.  
  2949.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  2950.     }
  2951.     else
  2952.         DeleteMsgItem((struct MsgItem *)Msg);
  2953.  
  2954.     return(NULL);
  2955. }
  2956.  
  2957. STRPTR
  2958. RexxDuplex(struct RexxPkt *Pkt)
  2959. {
  2960.     enum    {    ARG_DUPLEX_FULL,ARG_DUPLEX_HALF };
  2961.  
  2962.     LONG OldMode;
  2963.     LONG Mode;
  2964.  
  2965.     if(Args[ARG_DUPLEX_FULL])
  2966.         Mode = DUPLEX_FULL;
  2967.  
  2968.     if(Args[ARG_DUPLEX_HALF])
  2969.         Mode = DUPLEX_HALF;
  2970.  
  2971.     OldMode = Config->SerialConfig->Duplex;
  2972.  
  2973.     if(Config->SerialConfig->Duplex != Mode)
  2974.     {
  2975.         Config->SerialConfig->Duplex = Mode;
  2976.  
  2977.         UpdateRequired = TRUE;
  2978.  
  2979.         ConfigChanged = TRUE;
  2980.     }
  2981.  
  2982.     return(CreateArgstring(DuplexMappings[OldMode],strlen(DuplexMappings[OldMode])));
  2983. }
  2984.  
  2985. STRPTR
  2986. RexxFault(struct RexxPkt *Pkt)
  2987. {
  2988.     enum    {    ARG_FAULT_CODE };
  2989.  
  2990.     LONG Code = *(LONG *)Args[ARG_FAULT_CODE];
  2991.     UBYTE RexxResultString[MAX_FILENAME_LENGTH];
  2992.     STRPTR Result;
  2993.  
  2994.     if(Code >= ERR10_001 && Code <= ERR10_048)
  2995.         Result = LocaleString(MSG_AREXX_SYSERR10_001_TXT + Code - ERR10_001);
  2996.     else
  2997.     {
  2998.         if(Code >= TERMERROR_NO_DATA_TO_PROCESS && Code <= TERMERROR_WRONG_LIST)
  2999.             Result = LocaleString(MSG_AREXX_HOSTERR_000_TXT + Code - TERMERROR_NO_DATA_TO_PROCESS);
  3000.         else
  3001.         {
  3002.             Fault(Code,NULL,RexxResultString,sizeof(RexxResultString));
  3003.  
  3004.             Result = RexxResultString;
  3005.         }
  3006.     }
  3007.  
  3008.     return(CreateResult(Result,ResultCode));
  3009. }
  3010.  
  3011. STRPTR
  3012. RexxGetClip(struct RexxPkt *Pkt)
  3013. {
  3014.     enum    {    ARG_GETCLIP_UNIT };
  3015.  
  3016.     struct IFFHandle *Handle;
  3017.     STRPTR ResultBuffer;
  3018.     LONG Unit;
  3019.     LONG Error;
  3020.  
  3021.     if(Args[ARG_GETCLIP_UNIT])
  3022.         Unit = *(LONG *)Args[ARG_GETCLIP_UNIT];
  3023.     else
  3024.         Unit = Config->ClipConfig->ClipboardUnit;
  3025.  
  3026.     ResultBuffer = NULL;
  3027.  
  3028.     if(Handle = OpenIFFClip(Unit,MODE_OLDFILE))
  3029.     {
  3030.         if(!(Error = StopChunk(Handle,ID_FTXT,ID_CHRS)))
  3031.         {
  3032.             if(!ParseIFF(Handle,IFFPARSE_SCAN))
  3033.             {
  3034.                 struct ContextNode *ContextNode;
  3035.  
  3036.                 ContextNode = CurrentChunk(Handle);
  3037.  
  3038.                 if(ContextNode->cn_Type == ID_FTXT && ContextNode->cn_Size > 0)
  3039.                 {
  3040.                     STRPTR Result;
  3041.  
  3042.                     if(Result = (STRPTR)AllocVecPooled(ContextNode->cn_Size,MEMF_ANY))
  3043.                     {
  3044.                         if(ReadIFFBytes(Handle,Result,ContextNode->cn_Size))
  3045.                             ResultBuffer = CreateArgstring(Result,ContextNode->cn_Size);
  3046.  
  3047.                         FreeVecPooled(Result);
  3048.                     }
  3049.                     else
  3050.                         Error = ERROR_NO_FREE_STORE;
  3051.                 }
  3052.                 else
  3053.                     ResultCode[0] = RC_WARN;
  3054.             }
  3055.             else
  3056.                 Error = ERROR_OBJECT_NOT_FOUND;
  3057.         }
  3058.  
  3059.         CloseIFFClip(Handle);
  3060.     }
  3061.     else
  3062.         Error = IoErr();
  3063.  
  3064.     if(Error)
  3065.     {
  3066.         ResultCode[0] = RC_ERROR;
  3067.         ResultCode[1] = Error;
  3068.     }
  3069.  
  3070.     return(ResultBuffer);
  3071. }
  3072.  
  3073. STRPTR
  3074. RexxGoOnline(struct RexxPkt *Pkt)
  3075. {
  3076.     struct DataMsg *Msg;
  3077.  
  3078.     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  3079.     {
  3080.         Msg->Type = DATAMSGTYPE_GOONLINE;
  3081.  
  3082.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  3083.     }
  3084.     else
  3085.         ResultCode[0] = RC_WARN;
  3086.  
  3087.     return(NULL);
  3088. }
  3089.  
  3090. STRPTR
  3091. RexxHangup(struct RexxPkt *Pkt)
  3092. {
  3093.     struct DataMsg *Msg;
  3094.  
  3095.     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  3096.     {
  3097.         Msg->Type = DATAMSGTYPE_HANGUP;
  3098.         Msg->Data = (UBYTE *)Pkt->RexxMsg;
  3099.  
  3100.             /* The main process must reply this message when it takes care
  3101.              * of the event.
  3102.              */
  3103.  
  3104.         Pkt->RexxMsg = NULL;
  3105.  
  3106.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  3107.     }
  3108.     else
  3109.         ResultCode[0] = RC_WARN;
  3110.  
  3111.     return(NULL);
  3112. }
  3113.  
  3114. STRPTR
  3115. RexxHelp(struct RexxPkt *Pkt)
  3116. {
  3117.     enum    {    ARG_HELP_COMMAND,ARG_HELP_PROMPT };
  3118.  
  3119.     if(Args[ARG_HELP_PROMPT])
  3120.         GuideSetup();
  3121.     else
  3122.     {
  3123.         LONG i;
  3124.  
  3125.         for(i = 0 ; i < CommandTableSize ; i++)
  3126.         {
  3127.             if(!Stricmp(Args[ARG_HELP_COMMAND],CommandTable[i].Name))
  3128.             {
  3129.                 if(CommandTable[i].Arguments)
  3130.                     return(CreateResult(CommandTable[i].Arguments,ResultCode));
  3131.                 else
  3132.                     return(CreateResult(",",ResultCode));
  3133.             }
  3134.         }
  3135.  
  3136.         ResultCode[0] = RC_ERROR;
  3137.         ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  3138.     }
  3139.  
  3140.     return(NULL);
  3141. }
  3142.  
  3143. STRPTR
  3144. RexxOpenDevice(struct RexxPkt *Pkt)
  3145. {
  3146.     enum    {    ARG_OPENDEVICE_NAME,ARG_OPENDEVICE_UNIT };
  3147.  
  3148.     if(ReadRequest)
  3149.     {
  3150.         ResultCode[0] = RC_ERROR;
  3151.         ResultCode[1] = TERMERROR_DEVICE_DRIVER_STILL_OPEN;
  3152.  
  3153.         return(NULL);
  3154.     }
  3155.     else
  3156.     {
  3157.         UBYTE Result[MAX_FILENAME_LENGTH+10];
  3158.  
  3159.         LimitedSPrintf(sizeof(Result),"\"%s\" %ld",Config->SerialConfig->SerialDevice,Config->SerialConfig->UnitNumber);
  3160.  
  3161.         if(Args[ARG_OPENDEVICE_NAME])
  3162.         {
  3163.             strcpy(Config->SerialConfig->SerialDevice,Args[ARG_OPENDEVICE_NAME]);
  3164.  
  3165.             ConfigChanged = TRUE;
  3166.         }
  3167.  
  3168.         if(Args[ARG_OPENDEVICE_UNIT])
  3169.         {
  3170.             Config->SerialConfig->UnitNumber = *(LONG *)Args[ARG_OPENDEVICE_UNIT];
  3171.  
  3172.             ConfigChanged = TRUE;
  3173.         }
  3174.  
  3175.         BlockWindows();
  3176.  
  3177.         ReopenSerial();
  3178.  
  3179.         ReleaseWindows();
  3180.  
  3181.         return(CreateArgstring(Result,strlen(Result)));
  3182.     }
  3183. }
  3184.  
  3185. STRPTR
  3186. RexxParity(struct RexxPkt *Pkt)
  3187. {
  3188.     enum    {    ARG_PARITY_EVEN,ARG_PARITY_ODD,ARG_PARITY_NONE,ARG_PARITY_MARK,ARG_PARITY_SPACE };
  3189.  
  3190.     LONG OldMode;
  3191.     LONG Mode;
  3192.  
  3193.     if(Args[ARG_PARITY_EVEN])
  3194.         Mode = PARITY_EVEN;
  3195.  
  3196.     if(Args[ARG_PARITY_ODD])
  3197.         Mode = PARITY_ODD;
  3198.  
  3199.     if(Args[ARG_PARITY_NONE])
  3200.         Mode = PARITY_NONE;
  3201.  
  3202.     if(Args[ARG_PARITY_MARK])
  3203.         Mode = PARITY_MARK;
  3204.  
  3205.     if(Args[ARG_PARITY_SPACE])
  3206.         Mode = PARITY_SPACE;
  3207.  
  3208.     OldMode = Config->SerialConfig->Parity;
  3209.  
  3210.     if(Config->SerialConfig->Parity != Mode)
  3211.     {
  3212.         Config->SerialConfig->Parity = Mode;
  3213.  
  3214.         UpdateRequired = TRUE;
  3215.  
  3216.         ConfigChanged = TRUE;
  3217.     }
  3218.  
  3219.     return(CreateArgstring(ParityMappings[OldMode],strlen(ParityMappings[OldMode])));
  3220. }
  3221.  
  3222. STRPTR
  3223. RexxPasteClip(struct RexxPkt *Pkt)
  3224. {
  3225.     enum    {    ARG_PASTECLIP_UNIT };
  3226.  
  3227.     struct DataMsg *Msg;
  3228.     LONG Unit;
  3229.  
  3230.     if(Args[ARG_PASTECLIP_UNIT])
  3231.         Unit = *(LONG *)Args[ARG_PASTECLIP_UNIT];
  3232.     else
  3233.         Unit = Config->ClipConfig->ClipboardUnit;
  3234.  
  3235.     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  3236.     {
  3237.         Msg->Type = DATAMSGTYPE_WRITECLIP;
  3238.         Msg->Size = Unit;
  3239.  
  3240.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  3241.     }
  3242.     else
  3243.     {
  3244.         ResultCode[0] = RC_ERROR;
  3245.         ResultCode[1] = ERROR_NO_FREE_STORE;
  3246.     }
  3247.  
  3248.     return(NULL);
  3249. }
  3250.  
  3251. STRPTR
  3252. RexxProcessIO(struct RexxPkt *Pkt)
  3253. {
  3254.     enum    {    ARG_PROCESSIO_ON,ARG_PROCESSIO_OFF };
  3255.  
  3256.     BOOL OldState;
  3257.  
  3258.     OldState = ProcessIO;
  3259.  
  3260.     if(Args[ARG_PROCESSIO_ON])
  3261.         ProcessIO = TRUE;
  3262.  
  3263.     if(Args[ARG_PROCESSIO_OFF])
  3264.         ProcessIO = FALSE;
  3265.  
  3266.     if(OldState != ProcessIO)
  3267.     {
  3268.         if(ProcessIO)
  3269.             RestartSerial();
  3270.  
  3271.         UpdateSerialJob();
  3272.  
  3273.         if(!ProcessIO)
  3274.             ClearSerial();
  3275.     }
  3276.  
  3277.     return(CreateArgstring(BooleanMappings[OldState],strlen(BooleanMappings[OldState])));
  3278. }
  3279.  
  3280. STRPTR
  3281. RexxProtocol(struct RexxPkt *Pkt)
  3282. {
  3283.     enum    {    ARG_PROTOCOL_NONE,ARG_PROTOCOL_RTSCTS,ARG_PROTOCOL_RTSCTSDTR };
  3284.  
  3285.     LONG OldMode;
  3286.     LONG Mode;
  3287.  
  3288.     if(Args[ARG_PROTOCOL_NONE])
  3289.         Mode = HANDSHAKING_NONE;
  3290.  
  3291.     if(Args[ARG_PROTOCOL_RTSCTS])
  3292.         Mode = HANDSHAKING_RTSCTS;
  3293.  
  3294.     if(Args[ARG_PROTOCOL_RTSCTSDTR])
  3295.         Mode = HANDSHAKING_RTSCTS_DSR;
  3296.  
  3297.     OldMode = Config->SerialConfig->HandshakingProtocol;
  3298.  
  3299.     if(Config->SerialConfig->HandshakingProtocol != Mode)
  3300.     {
  3301.         Config->SerialConfig->HandshakingProtocol = Mode;
  3302.  
  3303.         UpdateRequired = TRUE;
  3304.  
  3305.         ConfigChanged = TRUE;
  3306.     }
  3307.  
  3308.     return(CreateArgstring(HandshakingMappings[OldMode],strlen(HandshakingMappings[OldMode])));
  3309. }
  3310.  
  3311. STRPTR
  3312. RexxPutClip(struct RexxPkt *Pkt)
  3313. {
  3314.     enum    {    ARG_PUTCLIP_UNIT,ARG_PUTCLIP_TEXT };
  3315.  
  3316.     struct IFFHandle *Handle;
  3317.     LONG Unit,Error;
  3318.  
  3319.     if(Args[ARG_PUTCLIP_UNIT])
  3320.         Unit = *(LONG *)Args[ARG_PUTCLIP_UNIT];
  3321.     else
  3322.         Unit = Config->ClipConfig->ClipboardUnit;
  3323.  
  3324.     if(Handle = OpenIFFClip(Unit,MODE_NEWFILE))
  3325.     {
  3326.         if(!(Error = PushChunk(Handle,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN)))
  3327.         {
  3328.             Error = AddIFFChunkBytes(Handle,ID_CHRS,Args[ARG_PUTCLIP_TEXT],strlen(Args[ARG_PUTCLIP_TEXT]));
  3329.         }
  3330.  
  3331.         if(!Error)
  3332.             Error = PopChunk(Handle);
  3333.  
  3334.         CloseIFFClip(Handle);
  3335.     }
  3336.     else
  3337.         Error = IoErr();
  3338.  
  3339.     if(Error)
  3340.     {
  3341.         ResultCode[0] = RC_ERROR;
  3342.         ResultCode[1] = Error;
  3343.     }
  3344.  
  3345.     return(NULL);
  3346. }
  3347.  
  3348. STRPTR
  3349. RexxQuit(struct RexxPkt *Pkt)
  3350. {
  3351.     enum    {    ARG_QUIT_FORCE };
  3352.  
  3353.     struct DataMsg *Msg;
  3354.  
  3355.     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  3356.     {
  3357.         Pkt->RexxMsg->rm_Result1 = RC_WARN;
  3358.         Pkt->RexxMsg->rm_Result2 = 0;
  3359.  
  3360.         ReplyMsg((struct Message *)Pkt->RexxMsg);
  3361.  
  3362.         Pkt->RexxMsg = NULL;
  3363.  
  3364.         Msg->Type = DATAMSGTYPE_MENU;
  3365.         Msg->Size = MEN_QUIT;
  3366.  
  3367.         if(Args[ARG_QUIT_FORCE])
  3368.             Msg->Data = (APTR)SHIFT_KEY;
  3369.         else
  3370.             Msg->Data = NULL;
  3371.  
  3372.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  3373.     }
  3374.     else
  3375.     {
  3376.         ResultCode[0] = RC_ERROR;
  3377.         ResultCode[1] = ERROR_NO_FREE_STORE;
  3378.     }
  3379.  
  3380.     return(NULL);
  3381. }
  3382.  
  3383. STRPTR
  3384. RexxRedial(struct RexxPkt *Pkt)
  3385. {
  3386.     struct DataMsg *Msg;
  3387.  
  3388.     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  3389.     {
  3390.         Msg->Type = DATAMSGTYPE_REDIAL;
  3391.  
  3392.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  3393.     }
  3394.     else
  3395.         ResultCode[0] = RC_WARN;
  3396.  
  3397.     return(NULL);
  3398. }
  3399.  
  3400. STRPTR
  3401. RexxRequestNotify(struct RexxPkt *Pkt)
  3402. {
  3403.     enum    {    ARG_REQUESTNOTIFY_TITLE,ARG_REQUESTNOTIFY_PROMPT };
  3404.  
  3405.     struct EasyStruct Easy;
  3406.  
  3407.     Easy.es_StructSize        = sizeof(struct EasyStruct);
  3408.     Easy.es_Flags            = NULL;
  3409.     Easy.es_TextFormat        = Args[ARG_REQUESTNOTIFY_PROMPT];
  3410.     Easy.es_GadgetFormat    = LocaleString(MSG_GLOBAL_CONTINUE_TXT);
  3411.  
  3412.     if(Args[ARG_REQUESTNOTIFY_TITLE])
  3413.         Easy.es_Title = Args[ARG_REQUESTNOTIFY_TITLE];
  3414.     else
  3415.         Easy.es_Title = LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  3416.  
  3417.     BlockWindows();
  3418.  
  3419.     EasyRequestArgs(Window,&Easy,NULL,NULL);
  3420.  
  3421.     ReleaseWindows();
  3422.  
  3423.     return(NULL);
  3424. }
  3425.  
  3426. STRPTR
  3427. RexxRequestNumber(struct RexxPkt *Pkt)
  3428. {
  3429.     enum    {    ARG_REQUESTNUMBER_DEFAULT,ARG_REQUESTNUMBER_PROMPT };
  3430.  
  3431.     UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  3432.  
  3433.     if(Args[ARG_REQUESTNUMBER_DEFAULT])
  3434.         LimitedSPrintf(sizeof(DummyBuffer),DummyBuffer,"%ld",*(LONG *)Args[ARG_REQUESTNUMBER_DEFAULT]);
  3435.     else
  3436.         DummyBuffer[0] = 0;
  3437.  
  3438.     BlockWindows();
  3439.  
  3440.     if(GetString(FALSE,FALSE,sizeof(DummyBuffer)-1,Args[ARG_REQUESTNUMBER_PROMPT],DummyBuffer))
  3441.     {
  3442.         STRPTR Index = DummyBuffer;
  3443.  
  3444.         while(*Index == ' ' || *Index == '\t')
  3445.             Index++;
  3446.  
  3447.         if(*Index)
  3448.         {
  3449.             LONG Value;
  3450.  
  3451.             if(StrToLong(DummyBuffer,&Value) == -1)
  3452.             {
  3453.                 ResultCode[0] = RC_ERROR;
  3454.                 ResultCode[1] = ERROR_BAD_NUMBER;
  3455.             }
  3456.             else
  3457.             {
  3458.                 ReleaseWindows();
  3459.  
  3460.                 LimitedSPrintf(sizeof(DummyBuffer),DummyBuffer,"%ld",Value);
  3461.  
  3462.                 return(CreateResult(DummyBuffer,ResultCode));
  3463.             }
  3464.         }
  3465.         else
  3466.             ResultCode[0] = RC_WARN;
  3467.     }
  3468.     else
  3469.         ResultCode[0] = RC_WARN;
  3470.  
  3471.     ReleaseWindows();
  3472.  
  3473.     return(NULL);
  3474. }
  3475.  
  3476. STRPTR
  3477. RexxRequestResponse(struct RexxPkt *Pkt)
  3478. {
  3479.     enum    {    ARG_REQUESTRESPONSE_TITLE,ARG_REQUESTRESPONSE_OPTIONS,
  3480.                 ARG_REQUESTRESPONSE_PROMPT
  3481.             };
  3482.  
  3483.     struct EasyStruct Easy;
  3484.     LONG Result;
  3485.  
  3486.     Easy.es_StructSize    = sizeof(struct EasyStruct);
  3487.     Easy.es_Flags        = NULL;
  3488.     Easy.es_TextFormat    = Args[ARG_REQUESTRESPONSE_PROMPT];
  3489.  
  3490.     if(Args[ARG_REQUESTRESPONSE_OPTIONS])
  3491.         Easy.es_GadgetFormat = Args[ARG_REQUESTRESPONSE_OPTIONS];
  3492.     else
  3493.         Easy.es_GadgetFormat = LocaleString(MSG_GLOBAL_YES_NO_TXT);
  3494.  
  3495.     if(Args[ARG_REQUESTRESPONSE_TITLE])
  3496.         Easy.es_Title = Args[ARG_REQUESTRESPONSE_TITLE];
  3497.     else
  3498.         Easy.es_Title = LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  3499.  
  3500.     BlockWindows();
  3501.  
  3502.     Result = EasyRequestArgs(Window,&Easy,NULL,NULL);
  3503.  
  3504.     ReleaseWindows();
  3505.  
  3506.     if(Result)
  3507.     {
  3508.         UBYTE DummyBuffer[20];
  3509.  
  3510.         LimitedSPrintf(sizeof(DummyBuffer),DummyBuffer,"%ld",Result);
  3511.  
  3512.         return(CreateResult(DummyBuffer,ResultCode));
  3513.     }
  3514.     else
  3515.     {
  3516.         ResultCode[0] = RC_WARN;
  3517.  
  3518.         return(NULL);
  3519.     }
  3520. }
  3521.  
  3522. STRPTR
  3523. RexxRequestString(struct RexxPkt *Pkt)
  3524. {
  3525.     enum    {    ARG_REQUESTSTRING_SECRET,ARG_REQUESTSTRING_DEFAULT,ARG_REQUESTSTRING_PROMPT };
  3526.  
  3527.     UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  3528.  
  3529.     if(Args[ARG_REQUESTSTRING_DEFAULT])
  3530.         strcpy(DummyBuffer,Args[ARG_REQUESTSTRING_DEFAULT]);
  3531.     else
  3532.         DummyBuffer[0] = 0;
  3533.  
  3534.     BlockWindows();
  3535.  
  3536.     if(GetString(FALSE,Args[ARG_REQUESTSTRING_SECRET] != NULL,sizeof(DummyBuffer) - 1,Args[ARG_REQUESTSTRING_PROMPT],DummyBuffer))
  3537.     {
  3538.         ReleaseWindows();
  3539.  
  3540.         return(CreateResult(DummyBuffer,ResultCode));
  3541.     }
  3542.     else
  3543.         ResultCode[0] = RC_WARN;
  3544.  
  3545.     ReleaseWindows();
  3546.  
  3547.     return(NULL);
  3548. }
  3549.  
  3550. STRPTR
  3551. RexxReset(struct RexxPkt *Pkt)
  3552. {
  3553.     enum    {    ARG_CLEAR,ARG_STYLE,ARG_TEXT,ARG_TIMER };
  3554.  
  3555.     if(Args[ARG_CLEAR])
  3556.         RexxResetScreen(Pkt);
  3557.  
  3558.     if(Args[ARG_STYLE])
  3559.         RexxResetStyles(Pkt);
  3560.  
  3561.     if(Args[ARG_TEXT])
  3562.         RexxResetText(Pkt);
  3563.  
  3564.     if(Args[ARG_TIMER])
  3565.         RexxResetTimer(Pkt);
  3566.  
  3567.     return(NULL);
  3568. }
  3569.  
  3570. STRPTR
  3571. RexxResetScreen(struct RexxPkt *UnusedPkt)
  3572. {
  3573.     ConResetTerminal();
  3574.  
  3575.     return(NULL);
  3576. }
  3577.  
  3578. STRPTR
  3579. RexxResetStyles(struct RexxPkt *UnusedPkt)
  3580. {
  3581.     ConResetStyles();
  3582.  
  3583.     return(NULL);
  3584. }
  3585.  
  3586. STRPTR
  3587. RexxResetText(struct RexxPkt *UnusedPkt)
  3588. {
  3589.     ConResetFont();
  3590.  
  3591.     return(NULL);
  3592. }
  3593.  
  3594. STRPTR
  3595. RexxResetTimer(struct RexxPkt *UnusedPkt)
  3596. {
  3597.     Forbid();
  3598.  
  3599.     if(StatusProcess)
  3600.         Signal((struct Task *)StatusProcess,SIG_RESETTIME);
  3601.  
  3602.     Permit();
  3603.  
  3604.     return(NULL);
  3605. }
  3606.  
  3607. STRPTR
  3608. RexxSave(struct RexxPkt *Pkt)
  3609. {
  3610.     enum    {    ARG_SAVE_FROM };
  3611.  
  3612.     Args[1] = Args[ARG_SAVE_FROM];
  3613.     Args[0] = NULL;
  3614.  
  3615.     return(RexxSaveAs(Pkt));
  3616. }
  3617.  
  3618. STRPTR
  3619. RexxSend(struct RexxPkt *Pkt)
  3620. {
  3621.     enum    {    ARG_SEND_NOECHO,ARG_SEND_LOCAL,ARG_SEND_LITERAL,ARG_SEND_BYTE,ARG_SEND_TEXT };
  3622.  
  3623.     if(Args[ARG_SEND_LOCAL])
  3624.     {
  3625.         if(!Args[ARG_SEND_NOECHO])
  3626.         {
  3627.             if(Marking)
  3628.                 WindowMarkerStop();
  3629.  
  3630.             if(Args[ARG_SEND_TEXT])
  3631.             {
  3632.                 if(Args[ARG_SEND_LITERAL])
  3633.                     ConProcess(Args[ARG_SEND_TEXT],strlen(Args[ARG_SEND_TEXT]));
  3634.                 else
  3635.                     ConsoleCommand(Args[ARG_SEND_TEXT]);
  3636.             }
  3637.             else
  3638.             {
  3639.                 UBYTE Byte = *(LONG *)Args[ARG_SEND_BYTE];
  3640.  
  3641.                 ConProcess(&Byte,1);
  3642.             }
  3643.         }
  3644.     }
  3645.     else
  3646.     {
  3647.         BOOL OldSettings;
  3648.  
  3649.         OldSettings = SetConsoleQuiet((BOOL)(Args[ARG_SEND_NOECHO] != NULL));
  3650.  
  3651.         if(Args[ARG_SEND_TEXT])
  3652.         {
  3653.             if(Args[ARG_SEND_LITERAL])
  3654.                 SerWrite(Args[ARG_SEND_TEXT],strlen(Args[ARG_SEND_TEXT]));
  3655.             else
  3656.                 SerialCommand(Args[ARG_SEND_TEXT]);
  3657.         }
  3658.         else
  3659.         {
  3660.             UBYTE Byte = *(LONG *)Args[ARG_SEND_BYTE];
  3661.  
  3662.             SerWrite(&Byte,1);
  3663.         }
  3664.  
  3665.         SetConsoleQuiet(OldSettings);
  3666.     }
  3667.  
  3668.     return(NULL);
  3669. }
  3670.  
  3671. STRPTR
  3672. RexxSendBreak(struct RexxPkt *Pkt)
  3673. {
  3674.     if(WriteRequest)
  3675.         SendBreak();
  3676.     else
  3677.         ResultCode[0] = RC_WARN;
  3678.  
  3679.     return(NULL);
  3680. }
  3681.  
  3682. STRPTR
  3683. RexxSpeak(struct RexxPkt *Pkt)
  3684. {
  3685.     enum    {    ARG_SPEAK_TEXT };
  3686.  
  3687.     if(SpeechConfig.Enabled && English)
  3688.         Say(Args[ARG_SPEAK_TEXT]);
  3689.     else
  3690.         ResultCode[0] = RC_WARN;
  3691.  
  3692.     return(NULL);
  3693. }
  3694.  
  3695. STRPTR
  3696. RexxStopBits(struct RexxPkt *Pkt)
  3697. {
  3698.     enum    {    ARG_STOPBITS_0,ARG_STOPBITS_1 };
  3699.  
  3700.     LONG Bits;
  3701.     UBYTE Number[10];
  3702.  
  3703.     LimitedSPrintf(sizeof(Number),Number,"%ld",Config->SerialConfig->StopBits);
  3704.  
  3705.     if(Args[ARG_STOPBITS_0])
  3706.         Bits = 0;
  3707.  
  3708.     if(Args[ARG_STOPBITS_1])
  3709.         Bits = 1;
  3710.  
  3711.     if(Config->SerialConfig->StopBits != Bits)
  3712.     {
  3713.         Config->SerialConfig->StopBits = Bits;
  3714.  
  3715.         UpdateRequired = TRUE;
  3716.  
  3717.         ConfigChanged = TRUE;
  3718.     }
  3719.  
  3720.     return(CreateArgstring(Number,strlen(Number)));
  3721. }
  3722.  
  3723. STRPTR
  3724. RexxTextBuffer(struct RexxPkt *Pkt)
  3725. {
  3726.     enum    {    ARG_TEXTBUFFER_LOCK,ARG_TEXTBUFFER_UNLOCK };
  3727.  
  3728.     Forbid();
  3729.  
  3730.     if(Args[ARG_TEXTBUFFER_LOCK])
  3731.         BufferFrozen = TRUE;
  3732.  
  3733.     if(Args[ARG_TEXTBUFFER_UNLOCK])
  3734.         BufferFrozen = FALSE;
  3735.  
  3736.     ConOutputUpdate();
  3737.  
  3738.     Permit();
  3739.  
  3740.     CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  3741.  
  3742.     return(NULL);
  3743. }
  3744.  
  3745. STRPTR
  3746. RexxTimeout(struct RexxPkt *Pkt)
  3747. {
  3748.     enum    {    ARG_TIMEOUT_SECONDS,ARG_TIMEOUT_OFF };
  3749.  
  3750.     if(Args[ARG_TIMEOUT_OFF])
  3751.         RexxTimeoutVal = 0;
  3752.     else
  3753.         RexxTimeoutVal = *(LONG *)Args[ARG_TIMEOUT_SECONDS];
  3754.  
  3755.     return(NULL);
  3756.  
  3757. }
  3758.  
  3759. STRPTR
  3760. RexxTrap(struct RexxPkt *Pkt)
  3761. {
  3762.     enum    {    ARG_TRAP_ON,ARG_TRAP_OFF };
  3763.  
  3764.     BOOL Enabled;
  3765.  
  3766.     if(Args[ARG_TRAP_ON])
  3767.         Enabled = TRUE;
  3768.  
  3769.     if(Args[ARG_TRAP_OFF])
  3770.         Enabled = FALSE;
  3771.  
  3772.     CheckItem(MEN_DISABLE_TRAPS,Enabled != TRUE);
  3773.  
  3774.     if(GenericListCount(GenericListTable[GLIST_TRAP]) != 0 && Enabled)
  3775.         WatchTraps = TRUE;
  3776.     else
  3777.         WatchTraps = FALSE;
  3778.  
  3779.     return(NULL);
  3780. }
  3781.  
  3782. STRPTR
  3783. RexxWindow(struct RexxPkt *Pkt)
  3784. {
  3785.     enum    {    ARG_WINDOW_NAMES,ARG_WINDOW_OPEN,ARG_WINDOW_CLOSE,ARG_WINDOW_ACTIVATE,
  3786.                 ARG_WINDOW_MIN,ARG_WINDOW_MAX,ARG_WINDOW_FRONT,ARG_WINDOW_BACK,
  3787.                 ARG_WINDOW_TOP,ARG_WINDOW_BOTTOM,ARG_WINDOW_UP,ARG_WINDOW_DOWN
  3788.             };
  3789.  
  3790.     STRPTR    *Names = (STRPTR *)Args[ARG_WINDOW_NAMES];
  3791.     LONG     Index;
  3792.  
  3793.     while(*Names)
  3794.     {
  3795.         if((Index = ToWindow(*Names++)) != -1)
  3796.         {
  3797.             if(Args[ARG_WINDOW_OPEN])
  3798.             {
  3799.                 Forbid();
  3800.  
  3801.                 switch(Index)
  3802.                 {
  3803.                     case WINDOWID_BUFFER:
  3804.  
  3805.                         LaunchBuffer();
  3806.                         break;
  3807.  
  3808.                     case WINDOWID_UPLOAD_QUEUE:
  3809.  
  3810.                         CreateQueueProcess();
  3811.  
  3812.                         break;
  3813.  
  3814.                     case WINDOWID_REVIEW:
  3815.  
  3816.                         if(!ReviewWindow)
  3817.                             CreateReview();
  3818.  
  3819.                         break;
  3820.  
  3821.                     case WINDOWID_PACKET:
  3822.  
  3823.                         if(!PacketWindow)
  3824.                             CreatePacketWindow();
  3825.  
  3826.                         break;
  3827.  
  3828.                     case WINDOWID_FASTMACROS:
  3829.  
  3830.                         if(!FastWindow)
  3831.                             OpenFastWindow();
  3832.  
  3833.                         break;
  3834.  
  3835.                     case WINDOWID_STATUS:
  3836.  
  3837.                         if(!InfoWindow)
  3838.                             OpenInfoWindow();
  3839.  
  3840.                         break;
  3841.  
  3842.                     case WINDOWID_MAIN:
  3843.  
  3844.                         if(!IconTerminated)
  3845.                             IconTerminated = TRUE;
  3846.  
  3847.                         break;
  3848.  
  3849.                     case WINDOWID_SINGLE_CHAR_ENTRY:
  3850.  
  3851.                         if(Window)
  3852.                             OpenMatrixWindow(Window);
  3853.  
  3854.                         break;
  3855.                 }
  3856.  
  3857.                 Permit();
  3858.             }
  3859.  
  3860.             if(Args[ARG_WINDOW_CLOSE])
  3861.             {
  3862.                 Forbid();
  3863.  
  3864.                 switch(Index)
  3865.                 {
  3866.                     case WINDOWID_UPLOAD_QUEUE:
  3867.  
  3868.                         CloseQueueWindow();
  3869.                         break;
  3870.  
  3871.                     case WINDOWID_BUFFER:
  3872.  
  3873.                         TerminateBuffer();
  3874.                         break;
  3875.  
  3876.                     case WINDOWID_REVIEW:
  3877.  
  3878.                         if(ReviewWindow)
  3879.                             DeleteReview();
  3880.  
  3881.                         break;
  3882.  
  3883.                     case WINDOWID_PACKET:
  3884.  
  3885.                         if(PacketWindow)
  3886.                             DeletePacketWindow(FALSE);
  3887.  
  3888.                         break;
  3889.  
  3890.                     case WINDOWID_FASTMACROS:
  3891.  
  3892.                         if(FastWindow)
  3893.                             CloseFastWindow();
  3894.  
  3895.                         break;
  3896.  
  3897.                     case WINDOWID_STATUS:
  3898.  
  3899.                         if(InfoWindow)
  3900.                             CloseInfoWindow();
  3901.  
  3902.                         break;
  3903.  
  3904.                     case WINDOWID_MAIN:
  3905.  
  3906.                         if(Window)
  3907.                             ActivateJob(MainJobQueue,IconifyJob);
  3908.  
  3909.                         break;
  3910.  
  3911.                     case WINDOWID_SINGLE_CHAR_ENTRY:
  3912.  
  3913.                         CloseMatrixWindow();
  3914.                         break;
  3915.                 }
  3916.  
  3917.                 Permit();
  3918.             }
  3919.  
  3920.             if(Args[ARG_WINDOW_ACTIVATE])
  3921.             {
  3922.                 Forbid();
  3923.  
  3924.                 switch(Index)
  3925.                 {
  3926.                     case WINDOWID_UPLOAD_QUEUE:
  3927.  
  3928.                         CreateQueueProcess();
  3929.  
  3930.                         break;
  3931.  
  3932.                     case WINDOWID_BUFFER:
  3933.  
  3934.                         LaunchBuffer();
  3935.                         break;
  3936.  
  3937.                     case WINDOWID_REVIEW:
  3938.  
  3939.                         if(ReviewWindow)
  3940.                             BumpWindow(ReviewWindow);
  3941.  
  3942.                         break;
  3943.  
  3944.                     case WINDOWID_PACKET:
  3945.  
  3946.                         if(PacketWindow)
  3947.                             BumpWindow(PacketWindow);
  3948.  
  3949.                         break;
  3950.  
  3951.                     case WINDOWID_FASTMACROS:
  3952.  
  3953.                         if(FastWindow)
  3954.                             BumpWindow(FastWindow);
  3955.  
  3956.                         break;
  3957.  
  3958.                     case WINDOWID_STATUS:
  3959.  
  3960.                         if(InfoWindow)
  3961.                             BumpWindow(InfoWindow);
  3962.  
  3963.                         break;
  3964.  
  3965.                     case WINDOWID_MAIN:
  3966.  
  3967.                         if(Window)
  3968.                             BumpWindow(Window);
  3969.  
  3970.                         break;
  3971.  
  3972.                     case WINDOWID_SINGLE_CHAR_ENTRY:
  3973.  
  3974.                         if(MatrixWindow)
  3975.                             BumpWindow(MatrixWindow);
  3976.  
  3977.                         break;
  3978.                 }
  3979.  
  3980.                 Permit();
  3981.             }
  3982.  
  3983.             if(Args[ARG_WINDOW_MIN])
  3984.             {
  3985.                 struct Window *SomeWindow = NULL;
  3986.  
  3987.                 Forbid();
  3988.  
  3989.                 switch(Index)
  3990.                 {
  3991.                     case WINDOWID_REVIEW:
  3992.  
  3993.                         SomeWindow = ReviewWindow;
  3994.                         break;
  3995.  
  3996.                     case WINDOWID_PACKET:
  3997.  
  3998.                         SomeWindow = PacketWindow;
  3999.                         break;
  4000.  
  4001.                     case WINDOWID_FASTMACROS:
  4002.  
  4003.                         SomeWindow = FastWindow;
  4004.                         break;
  4005.  
  4006.                     case WINDOWID_STATUS:
  4007.  
  4008.                         SomeWindow = InfoWindow;
  4009.                         break;
  4010.                 }
  4011.  
  4012.                 if(SomeWindow)
  4013.                     ChangeWindowBox(SomeWindow,SomeWindow->LeftEdge,SomeWindow->TopEdge,SomeWindow->MinWidth,SomeWindow->MinHeight);
  4014.  
  4015.                 Permit();
  4016.             }
  4017.  
  4018.             if(Args[ARG_WINDOW_MAX])
  4019.             {
  4020.                 struct Window *SomeWindow = NULL;
  4021.  
  4022.                 Forbid();
  4023.  
  4024.                 switch(Index)
  4025.                 {
  4026.                     case WINDOWID_REVIEW:
  4027.  
  4028.                         SomeWindow = ReviewWindow;
  4029.                         break;
  4030.  
  4031.                     case WINDOWID_PACKET:
  4032.  
  4033.                         SomeWindow = PacketWindow;
  4034.                         break;
  4035.  
  4036.                     case WINDOWID_FASTMACROS:
  4037.  
  4038.                         SomeWindow = FastWindow;
  4039.                         break;
  4040.  
  4041.                     case WINDOWID_STATUS:
  4042.  
  4043.                         SomeWindow = InfoWindow;
  4044.                         break;
  4045.                 }
  4046.  
  4047.                 if(SomeWindow)
  4048.                     ChangeWindowBox(SomeWindow,0,0,SomeWindow->MaxWidth,SomeWindow->MaxHeight);
  4049.  
  4050.                 Permit();
  4051.             }
  4052.  
  4053.             if(Args[ARG_WINDOW_FRONT])
  4054.             {
  4055.                 Forbid();
  4056.  
  4057.                 switch(Index)
  4058.                 {
  4059.                     case WINDOWID_UPLOAD_QUEUE:
  4060.  
  4061.                         CreateQueueProcess();
  4062.  
  4063.                         break;
  4064.  
  4065.                     case WINDOWID_BUFFER:
  4066.  
  4067.                         LaunchBuffer();
  4068.                         break;
  4069.  
  4070.                     case WINDOWID_REVIEW:
  4071.  
  4072.                         if(ReviewWindow)
  4073.                             WindowToFront(ReviewWindow);
  4074.  
  4075.                         break;
  4076.  
  4077.                     case WINDOWID_PACKET:
  4078.  
  4079.                         if(PacketWindow)
  4080.                             WindowToFront(PacketWindow);
  4081.  
  4082.                         break;
  4083.  
  4084.                     case WINDOWID_FASTMACROS:
  4085.  
  4086.                         if(FastWindow)
  4087.                             WindowToFront(FastWindow);
  4088.  
  4089.                         break;
  4090.  
  4091.                     case WINDOWID_STATUS:
  4092.  
  4093.                         if(InfoWindow)
  4094.                             WindowToFront(InfoWindow);
  4095.  
  4096.                         break;
  4097.  
  4098.                     case WINDOWID_MAIN:
  4099.  
  4100.                         if(Window)
  4101.                             WindowToFront(Window);
  4102.  
  4103.                         break;
  4104.  
  4105.                     case WINDOWID_SINGLE_CHAR_ENTRY:
  4106.  
  4107.                         if(MatrixWindow)
  4108.                             WindowToFront(MatrixWindow);
  4109.  
  4110.                         break;
  4111.                 }
  4112.  
  4113.                 Permit();
  4114.             }
  4115.  
  4116.             if(Args[ARG_WINDOW_BACK])
  4117.             {
  4118.                 Forbid();
  4119.  
  4120.                 switch(Index)
  4121.                 {
  4122.                     case WINDOWID_REVIEW:
  4123.  
  4124.                         if(ReviewWindow)
  4125.                             WindowToBack(ReviewWindow);
  4126.  
  4127.                         break;
  4128.  
  4129.                     case WINDOWID_PACKET:
  4130.  
  4131.                         if(PacketWindow)
  4132.                             WindowToBack(PacketWindow);
  4133.  
  4134.                         break;
  4135.  
  4136.                     case WINDOWID_FASTMACROS:
  4137.  
  4138.                         if(FastWindow)
  4139.                             WindowToBack(FastWindow);
  4140.  
  4141.                         break;
  4142.  
  4143.                     case WINDOWID_STATUS:
  4144.  
  4145.                         if(InfoWindow)
  4146.                             WindowToBack(InfoWindow);
  4147.  
  4148.                         break;
  4149.  
  4150.                     case WINDOWID_MAIN:
  4151.  
  4152.                         if(Window)
  4153.                             WindowToBack(Window);
  4154.  
  4155.                         break;
  4156.  
  4157.                     case WINDOWID_SINGLE_CHAR_ENTRY:
  4158.  
  4159.                         if(MatrixWindow)
  4160.                             WindowToBack(MatrixWindow);
  4161.  
  4162.                         break;
  4163.                 }
  4164.  
  4165.                 Permit();
  4166.             }
  4167.  
  4168.             Forbid();
  4169.  
  4170.             if(Index == WINDOW_REVIEW && ReviewWindow)
  4171.             {
  4172.                 if(Args[ARG_WINDOW_TOP])
  4173.                     MoveReview(REVIEW_MOVE_TOP);
  4174.  
  4175.                 if(Args[ARG_WINDOW_BOTTOM])
  4176.                     MoveReview(REVIEW_MOVE_BOTTOM);
  4177.  
  4178.                 if(Args[ARG_WINDOW_UP])
  4179.                     MoveReview(REVIEW_MOVE_UP);
  4180.  
  4181.                 if(Args[ARG_WINDOW_DOWN])
  4182.                     MoveReview(REVIEW_MOVE_DOWN);
  4183.             }
  4184.  
  4185.             Permit();
  4186.         }
  4187.     }
  4188.  
  4189.     return(NULL);
  4190. }
  4191.  
  4192. STATIC VOID
  4193. RexxLaunchCleanup(LaunchMsg *Startup)
  4194. {
  4195.     struct RexxPkt *Pkt = Startup->RexxPkt;
  4196.  
  4197.     ResultCode[0] = Startup->Result;
  4198.     ResultCode[1] = Startup->Result2;
  4199.  
  4200.     RexxPktCleanup(Pkt,NULL);
  4201. }
  4202.  
  4203. STRPTR
  4204. RexxRX(struct RexxPkt *Pkt)
  4205. {
  4206.     enum    {    ARG_RX_CONSOLE,ARG_RX_ASYNC,ARG_RX_COMMAND };
  4207.  
  4208.     LaunchMsg    *Startup;
  4209.     BOOL         Eaten;
  4210.  
  4211.     if(!(Startup = CreateRexxCmdLaunchMsg(Args[ARG_RX_COMMAND],Pkt,Args[ARG_RX_ASYNC] ? NULL : RexxLaunchCleanup)))
  4212.     {
  4213.         ResultCode[0] = RC_ERROR;
  4214.         ResultCode[1] = ERR10_013;
  4215.  
  4216.         RexxPktCleanup(Pkt,NULL);
  4217.  
  4218.         return(NULL);
  4219.     }
  4220.  
  4221.     if(Args[ARG_RX_ASYNC])
  4222.     {
  4223.         RexxPktCleanup(Pkt,NULL);
  4224.  
  4225.         Eaten = TRUE;
  4226.     }
  4227.     else
  4228.         Eaten = FALSE;
  4229.  
  4230.     if(LaunchSomething(Args[ARG_RX_CONSOLE],!Eaten,Startup))
  4231.     {
  4232.         ResultCode[0] = RC_ERROR;
  4233.         ResultCode[1] = IoErr();
  4234.     }
  4235.     else
  4236.     {
  4237.         if(Eaten)
  4238.             DeleteLaunchMsg(Startup);
  4239.     }
  4240.  
  4241.     if(!Eaten)
  4242.         RexxPktCleanup(Pkt,NULL);
  4243.  
  4244.     return(NULL);
  4245. }
  4246.  
  4247. STRPTR
  4248. RexxExecTool(struct RexxPkt *Pkt)
  4249. {
  4250.     enum    {    ARG_EXECTOOL_CONSOLE,ARG_EXECTOOL_ASYNC,ARG_EXECTOOL_PORT,ARG_EXECTOOL_COMMAND };
  4251.  
  4252.     UBYTE         CommandName[MAX_FILENAME_LENGTH];
  4253.     UBYTE         CommandArgs[MAX_FILENAME_LENGTH];
  4254.     STRPTR         Index = Args[ARG_EXECTOOL_COMMAND];
  4255.     LONG         i;
  4256.     BOOL         Eaten;
  4257.     LaunchMsg    *Startup;
  4258.  
  4259.     while(*Index == ' ' || *Index == '\t')
  4260.         Index++;
  4261.  
  4262.     for(i = 0 ; Index[i] != ' ' && Index[i] != '\t' ; i++)
  4263.         CommandName[i] = Index[i];
  4264.  
  4265.     CommandName[i] = 0;
  4266.  
  4267.     Index += i;
  4268.  
  4269.     while(*Index == ' ' || *Index == '\t')
  4270.         Index++;
  4271.  
  4272.     if(Args[ARG_EXECTOOL_PORT])
  4273.         LimitedSPrintf(sizeof(CommandArgs),CommandArgs,"%s %s\n",Index,RexxPortName);
  4274.     else
  4275.         LimitedSPrintf(sizeof(CommandArgs),CommandArgs,"%s\n",Index);
  4276.  
  4277.     LimitedStrcat(sizeof(CommandName),CommandName," ");
  4278.     LimitedStrcat(sizeof(CommandName),CommandName,CommandArgs);
  4279.  
  4280.     if(!(Startup = CreateProgramLaunchMsg(CommandName,NULL)))
  4281.     {
  4282.         ResultCode[0] = RC_ERROR;
  4283.         ResultCode[1] = ERR10_013;
  4284.  
  4285.         RexxPktCleanup(Pkt,NULL);
  4286.  
  4287.         return(NULL);
  4288.     }
  4289.  
  4290.     if(Args[ARG_EXECTOOL_ASYNC])
  4291.     {
  4292.         RexxPktCleanup(Pkt,NULL);
  4293.  
  4294.         Eaten = TRUE;
  4295.     }
  4296.     else
  4297.         Eaten = FALSE;
  4298.  
  4299.     if(LaunchSomething(Args[ARG_EXECTOOL_CONSOLE],FALSE,Startup))
  4300.     {
  4301.         if(!Eaten)
  4302.         {
  4303.             ResultCode[0] = RC_ERROR;
  4304.             ResultCode[1] = IoErr();
  4305.         }
  4306.     }
  4307.     else
  4308.         DeleteLaunchMsg(Startup);
  4309.  
  4310.     if(!Eaten)
  4311.         RexxPktCleanup(Pkt,NULL);
  4312.  
  4313.     return(NULL);
  4314. }
  4315.  
  4316. STRPTR
  4317. RexxRead(struct RexxPkt *Pkt)
  4318. {
  4319.     enum    {    ARG_READ_NUM,ARG_READ_CR,ARG_READ_NOECHO,ARG_READ_VERBATIM,
  4320.                 ARG_TIMEOUT,ARG_TERMINATOR,ARG_READ_PROMPT
  4321.             };
  4322.  
  4323.     LONG MaxBytesToRead;
  4324.     LONG BytesRead;
  4325.     ULONG Signals;
  4326.     STRPTR Buffer;
  4327.     STRPTR Result;
  4328.     LONG Timeout;
  4329.     BOOL Done;
  4330.     BOOL Echo;
  4331.     WORD Terminator;
  4332.  
  4333.     if(!ReadRequest || !WriteRequest)
  4334.     {
  4335.         ResultCode[0] = RC_WARN;
  4336.  
  4337.         return(NULL);
  4338.     }
  4339.  
  4340.     if(Args[ARG_READ_NUM])
  4341.     {
  4342.         MaxBytesToRead = *(LONG *)Args[ARG_READ_NUM] + 1;
  4343.  
  4344.         if(MaxBytesToRead < 1)
  4345.         {
  4346.             ResultCode[0] = RC_ERROR;
  4347.             ResultCode[1] = ERROR_BAD_NUMBER;
  4348.  
  4349.             return(NULL);
  4350.         }
  4351.  
  4352.         if(MaxBytesToRead > MAX_RESULT_LEN + 1)
  4353.             MaxBytesToRead = MAX_RESULT_LEN + 1;
  4354.     }
  4355.     else
  4356.         MaxBytesToRead = MAX_RESULT_LEN + 1;
  4357.  
  4358.     if(!(Buffer = (STRPTR)AllocVecPooled(MaxBytesToRead,MEMF_ANY)))
  4359.     {
  4360.         ResultCode[0] = RC_ERROR;
  4361.         ResultCode[1] = ERROR_NO_FREE_STORE;
  4362.  
  4363.         return(NULL);
  4364.     }
  4365.  
  4366.     if(Args[ARG_READ_PROMPT])
  4367.         SerialCommand(Args[ARG_READ_PROMPT]);
  4368.  
  4369.     if(Args[ARG_READ_NOECHO])
  4370.         Echo = FALSE;
  4371.     else
  4372.         Echo = TRUE;
  4373.  
  4374.     if(Args[ARG_TIMEOUT])
  4375.         Timeout = *(LONG *)Args[ARG_TIMEOUT];
  4376.     else
  4377.         Timeout = RexxTimeoutVal;
  4378.  
  4379.     Terminator = -1;
  4380.  
  4381.     if(Args[ARG_TERMINATOR])
  4382.     {
  4383.         UBYTE LocalBuffer[256];
  4384.  
  4385.         if(TranslateString(Args[ARG_TERMINATOR],LocalBuffer) > 0)
  4386.             Terminator = LocalBuffer[0];
  4387.     }
  4388.  
  4389.     if(Timeout)
  4390.         StartTime(Timeout,0);
  4391.  
  4392.     Done = FALSE;
  4393.     BytesRead = 0;
  4394.  
  4395.     if(Args[ARG_READ_VERBATIM] || !ReceiveTable)
  4396.     {
  4397.         do
  4398.         {
  4399.             Signals = (*SerialWaitForData)(SIG_WINDOW | SIG_BREAK | SIG_TIMER);
  4400.  
  4401.             if(Signals & SIG_WINDOW)
  4402.                 while(RunJob(WindowJob));
  4403.  
  4404.             if(Signals & SIG_SERIAL)
  4405.             {
  4406.                 ULONG Length;
  4407.  
  4408.                 if(Length = (*SerialGetWaiting)())
  4409.                 {
  4410.                     if(Length > SerialBufferSize / 2)
  4411.                         Length = SerialBufferSize / 2;
  4412.  
  4413.                     if(Length > Config->SerialConfig->Quantum)
  4414.                         Length = Config->SerialConfig->Quantum;
  4415.  
  4416.                     if(Length = (*SerialRead)(ReadBuffer,Length))
  4417.                     {
  4418.                         BytesIn += Length;
  4419.  
  4420.                         if(Translate_CR_LF)
  4421.                             Length = (*Translate_CR_LF)(ReadBuffer,Length);
  4422.  
  4423.                         if(Length)
  4424.                         {
  4425.                             UBYTE *BufferPtr,c;
  4426.  
  4427.                             BufferPtr = ReadBuffer;
  4428.  
  4429.                             while(!Done && Length > 0)
  4430.                             {
  4431.                                 Length--;
  4432.  
  4433.                                 c = *BufferPtr++;
  4434.  
  4435.                                 if(c == Terminator)
  4436.                                 {
  4437.                                     if(Echo)
  4438.                                         ConProcess(&c,1);
  4439.  
  4440.                                     Done = TRUE;
  4441.                                     break;
  4442.                                 }
  4443.  
  4444.                                 switch(c)
  4445.                                 {
  4446.                                     case '\n':
  4447.  
  4448.                                         if(Echo)
  4449.                                             ConProcess(&c,1);
  4450.  
  4451.                                         break;
  4452.  
  4453.                                     case '\r':
  4454.  
  4455.                                         if(Args[ARG_READ_CR])
  4456.                                             Done = TRUE;
  4457.  
  4458.                                         if(Echo)
  4459.                                             ConProcess(&c,1);
  4460.  
  4461.                                         break;
  4462.  
  4463.                                     case '\b':
  4464.  
  4465.                                         if(BytesRead > 0)
  4466.                                         {
  4467.                                             BytesRead--;
  4468.  
  4469.                                             if(Echo)
  4470.                                                 ConProcess(&c,1);
  4471.                                         }
  4472.  
  4473.                                         break;
  4474.  
  4475.                                     case CONTROL_('X'):
  4476.  
  4477.                                         if(Echo)
  4478.                                         {
  4479.                                             while(BytesRead > 0)
  4480.                                             {
  4481.                                                 BytesRead--;
  4482.  
  4483.                                                 ConProcess("\b",1);
  4484.                                             }
  4485.                                         }
  4486.                                         else
  4487.                                             BytesRead = 0;
  4488.  
  4489.                                         break;
  4490.  
  4491.                                     default:
  4492.  
  4493.                                         if(BytesRead < MaxBytesToRead && ((c >= ' ' && c < 127) || c >= 160 || Config->TerminalConfig->FontMode == FONT_IBM))
  4494.                                         {
  4495.                                             Buffer[BytesRead++] = c;
  4496.  
  4497.                                             if(Echo)
  4498.                                                 ConProcess(&c,1);
  4499.                                         }
  4500.  
  4501.                                         break;
  4502.                                 }
  4503.                             }
  4504.                         }
  4505.                     }
  4506.                 }
  4507.             }
  4508.  
  4509.             if(Signals & (SIG_BREAK | SIG_TIMER))
  4510.             {
  4511.                 ResultCode[0] = RC_WARN;
  4512.  
  4513.                 Done = TRUE;
  4514.             }
  4515.         }
  4516.         while(!Done);
  4517.     }
  4518.     else
  4519.     {
  4520.         do
  4521.         {
  4522.             Signals = (*SerialWaitForData)(SIG_WINDOW | SIG_BREAK | SIG_TIMER);
  4523.  
  4524.             if(Signals & SIG_WINDOW)
  4525.                 while(RunJob(WindowJob));
  4526.  
  4527.             if(Signals & SIG_SERIAL)
  4528.             {
  4529.                 ULONG Length;
  4530.  
  4531.                 if(Length = (*SerialGetWaiting)())
  4532.                 {
  4533.                     if(Length > SerialBufferSize / 2)
  4534.                         Length = SerialBufferSize / 2;
  4535.  
  4536.                     if(Length > Config->SerialConfig->Quantum)
  4537.                         Length = Config->SerialConfig->Quantum;
  4538.  
  4539.                     if(Length = (*SerialRead)(ReadBuffer,Length))
  4540.                     {
  4541.                         BytesIn += Length;
  4542.  
  4543.                         if(Translate_CR_LF)
  4544.                             Length = (*Translate_CR_LF)(ReadBuffer,Length);
  4545.  
  4546.                         if(Length)
  4547.                         {
  4548.                             struct TranslationHandle Handle;
  4549.                             UBYTE c;
  4550.  
  4551.                             TranslateSetup(&Handle,ReadBuffer,Length,&c,1,ReceiveTable);
  4552.  
  4553.                             while(!Done && TranslateBuffer(&Handle))
  4554.                             {
  4555.                                 if(c == Terminator)
  4556.                                 {
  4557.                                     if(Echo)
  4558.                                         ConProcess(&c,1);
  4559.  
  4560.                                     Done = TRUE;
  4561.                                     break;
  4562.                                 }
  4563.  
  4564.                                 switch(c)
  4565.                                 {
  4566.                                     case '\n':
  4567.  
  4568.                                         if(Echo)
  4569.                                             ConProcess(&c,1);
  4570.  
  4571.                                         break;
  4572.  
  4573.                                     case '\r':
  4574.  
  4575.                                         if(Args[ARG_READ_CR])
  4576.                                             Done = TRUE;
  4577.  
  4578.                                         if(Echo)
  4579.                                             ConProcess(&c,1);
  4580.  
  4581.                                         break;
  4582.  
  4583.                                     case '\b':
  4584.  
  4585.                                         if(BytesRead > 0)
  4586.                                         {
  4587.                                             BytesRead--;
  4588.  
  4589.                                             if(Echo)
  4590.                                                 ConProcess(&c,1);
  4591.                                         }
  4592.  
  4593.                                         break;
  4594.  
  4595.                                     case CONTROL_('X'):
  4596.  
  4597.                                         if(Echo)
  4598.                                         {
  4599.                                             while(BytesRead > 0)
  4600.                                             {
  4601.                                                 BytesRead--;
  4602.  
  4603.                                                 ConProcess("\b",1);
  4604.                                             }
  4605.                                         }
  4606.                                         else
  4607.                                             BytesRead = 0;
  4608.  
  4609.                                         break;
  4610.  
  4611.                                     default:
  4612.  
  4613.                                         if(BytesRead < MaxBytesToRead && ((c >= ' ' && c < 127) || c >= 160 || Config->TerminalConfig->FontMode == FONT_IBM))
  4614.                                         {
  4615.                                             Buffer[BytesRead++] = c;
  4616.  
  4617.                                             if(Echo)
  4618.                                                 ConProcess(&c,1);
  4619.                                         }
  4620.  
  4621.                                         break;
  4622.                                 }
  4623.                             }
  4624.                         }
  4625.                     }
  4626.                 }
  4627.             }
  4628.  
  4629.             if(Signals & (SIG_BREAK | SIG_TIMER))
  4630.             {
  4631.                 ResultCode[0] = RC_WARN;
  4632.  
  4633.                 Done = TRUE;
  4634.             }
  4635.         }
  4636.         while(!Done);
  4637.     }
  4638.  
  4639.     StopTime();
  4640.  
  4641.     if(BytesRead > 0)
  4642.     {
  4643.         Buffer[BytesRead] = 0;
  4644.  
  4645.         Result = CreateResult(Buffer,ResultCode);
  4646.     }
  4647.     else
  4648.     {
  4649.         ResultCode[0] = RC_WARN;
  4650.         Result = NULL;
  4651.     }
  4652.  
  4653.     FreeVecPooled(Buffer);
  4654.  
  4655.     return(Result);
  4656. }
  4657.